Last active
September 9, 2018 16:29
-
-
Save Zorono/64cdb80c21c20aaec10b34a8ca1df198 to your computer and use it in GitHub Desktop.
Image Base64 Encoding...(PHP)
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
<?php | |
$img_url = (preg_match('/\%[0-9A-F]{2}|\+/', $_GET['url']) !== False ? urldecode($_GET['url']) : $_GET['url']); | |
if($img_content = @file_get_contents($img_url)) | |
{ | |
if(strlen(mime_content_type($img_url)) > 2 ? strpos(mime_content_type($img_url), 'image/') !== False : True) | |
{ | |
$_finfo = new finfo(); | |
$img_mime = $_finfo->file($img_url, FILEINFO_MIME_TYPE); | |
echo '<img src="data:' .(isset($img_mime) && strlen($img_mime) > 2 ? $img_mime : "image/jpeg"). ';base64,' .base64_encode($img_content). '" />'; | |
} | |
else | |
{ | |
header("HTTP/1.0 404 Not Found"); | |
} | |
} | |
else | |
{ | |
header("HTTP/1.0 404 Not Found"); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment