Last active
October 6, 2015 22:07
-
-
Save 321zeno/3060035 to your computer and use it in GitHub Desktop.
read image file for output as base64 in img tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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