Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
image encode Base64 PHP
$filename = 'anhaenger.jpg';
//$filename = 'anhaenger.png';
$path = 'img/' . $filename;
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
file_put_contents('base64/' . substr($filename, 0, (strrpos($filename, '.'))), $base64);
echo $base64;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.