WordPress\AiClient\Files\DTO
File::convertFileToBase64
Converts a local file to base64.
Method of the class: File{}
No Hooks.
Returns
String. The base64-encoded file data.
Usage
// private - for code of main (parent) class only $result = $this->convertFileToBase64( $filePath ): string;
- $filePath(string) (required)
- The path to the local file.
Changelog
| Since 0.1.0 | Introduced. |
File::convertFileToBase64() File::convertFileToBase64 code WP 7.0
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);
}