Php – How to convert an image to Base64 encoding

base64imagePHP

How can I convert an image from a URL to Base64 encoding?

Best Answer

I think that it should be:

$path = 'myfolder/myimage.png';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);