-
Notifications
You must be signed in to change notification settings - Fork 3
/
imgProxy.php
30 lines (28 loc) · 926 Bytes
/
imgProxy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
$remoteImage = $_GET["img"];
$allowedSites = [
"https://derpicdn.net" => function($url){
if (!preg_match("~https://derpicdn.net/img/view/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)[^.]*(\..*)*~",$url,$matches)){
return $url;
} else {
return "https://derpicdn.net/img/$matches[1]/$matches[2]/$matches[3]/$matches[4]/medium$matches[5]";
}
}
];
foreach ($allowedSites as $site => $mapping) {
//Check if it's on the allowed site's list
if (substr($remoteImage, 0, strlen($site)) === $site){
if ($mapping){
$remoteImage = $mapping($remoteImage);
}
$imginfo = getimagesize($remoteImage);
header("Content-type: ".$imginfo['mime']);
readfile($remoteImage);
die();
}
}
//If not try a redirect to see if they have CROS
//print $remoteImage;
//http_redirect($remoteImage);
header("Location: $remoteImage")
?>