-
-
Save carloscarucce/89329fa61997b3775487b0c155cda41f to your computer and use it in GitHub Desktop.
basic PHP image proxy (that works ... )
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 | |
$url = isset($_GET['url']) ? $_GET['url'] : null; | |
if (!$url) { | |
die('Please, inform URL'); | |
} | |
$imgInfo = getimagesize( $url ); | |
if ($imgInfo === false) { | |
die('Could not retrieve information'); | |
} | |
if (stripos($imgInfo['mime'], 'image/') === false) { | |
die('Invalid image file'); | |
} | |
header("Content-type: ".$imgInfo['mime']); | |
readfile( $url ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Looper1984 glad it helped. I would not leave error messages in a production environment, through.
You can hide it by changing a directive in your php.ini:
display_errors = off
. Or programmatically withini_set("display_errors", 0);
References:
Article: https://www.a2hosting.com/kb/developer-corner/php/using-php.ini-directives/php-error-messages/
S.O. Thread: https://stackoverflow.com/a/332206/3435728 (accepted answer teaches on how to enable logging too)