Skip to content

Instantly share code, notes, and snippets.

@321zeno
Last active October 6, 2015 22:07
Show Gist options
  • Save 321zeno/3060035 to your computer and use it in GitHub Desktop.
Save 321zeno/3060035 to your computer and use it in GitHub Desktop.
read image file for output as base64 in img tag
public function getImage($name){
$folder_path = '/physical/path/to/file/';
$image_path = $folder_path.$name;
$filetype = pathinfo($image_path, PATHINFO_EXTENSION);
if (file_exists($image_path)) {
$file_data = file_get_contents($image_path);
return 'data:image/' . $filetype . ';base64,' . base64_encode($file_data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment