Skip to content

Instantly share code, notes, and snippets.

@lnaia
Last active August 29, 2015 14:02
Show Gist options
  • Save lnaia/fcada8bc995e890256bc to your computer and use it in GitHub Desktop.
Save lnaia/fcada8bc995e890256bc to your computer and use it in GitHub Desktop.
Lazy friends, that cannot access some images, because of firewalls at their work. Lazy because they cannot code a simple way around. :(
<?php
try {
$image_path = $_GET['image'];
if (strlen($image_path) < 4){
echo 'n/a';
return;
}
$http = substr($image_path, 0, 4);
if (strtolower($http) != 'http') {
echo "Http missing from path";
return;
}
$image_name = basename($image_path);
$file_extension = substr($image_name, (strlen($image_name) - 3));
$file_extension = strtolower($file_extension);
if ($file_extension == 'jpg' || $file_extension == 'png' ||
$file_extension == 'gif' || $file_extension == 'jpeg') {
header('Content-Type: image/jpeg');
echo file_get_contents($image_path);
} else {
echo "Wrong file extension. Is it a picture?";
}
} catch (Exception $e) {
@error_log(json_encode($e->getTrace()));
echo 'nice try.';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment