File::convertFileToBase64( string $filePath ): string

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

Converts a local file to base64.

Parameters

$filePathstringrequired
The path to the local file.

Return

string The base64-encoded file data.

Source

private function convertFileToBase64(string $filePath): string
{
    $fileContent = @file_get_contents($filePath);
    if ($fileContent === \false) {
        throw new RuntimeException(sprintf('Unable to read file: %s', $filePath));
    }
    return base64_encode($fileContent);
}

Changelog

VersionDescription
0.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.