Skip to content

Instantly share code, notes, and snippets.

@bitkorn
Last active March 31, 2018 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitkorn/0cbb7c45f8b7638094377a4dd43567bc to your computer and use it in GitHub Desktop.
Save bitkorn/0cbb7c45f8b7638094377a4dd43567bc to your computer and use it in GitHub Desktop.
image encode Base64 PHP
<?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