How to convert an image to Base64 encoding

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);

Leave a Comment