-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.php
57 lines (47 loc) · 2.04 KB
/
proxy.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* used to load external resources, because sfw flash files cant do this because of policy issues
* need to add crossdomain.xml to all websites root whre we need to download files or use this proxy
*/
$srv = $_GET['srv'];
$path= $_GET['path'];
//if($srv=='tpsadminfuncs') $srv = 'http://srv1.toopro.org:3088/'; else die();
switch ($srv) {
case 'tpsadminfuncs': $srv = 'http://adm.toopro.org:3088/'; break;
case 'nfeya.com' : $srv = 'https://nfeya.com/'; break;
default: die();
}
$url = $srv . $path;
// Get the headers from the destination URL
$responseHeaders = get_headers($url, 1); //print_r($responseHeaders);die();
if(strpos($url, 'nfeya.com') !== FALSE) { //for imges we need headeres, for json not
foreach ($responseHeaders as $name => $value) {
if (is_array($value)) foreach ($value as $item) header("$name: $item", false);
else header("$name: $value", false);
}
}
//check if its webp image then it will echo webp and return true
$jpegConverted = checkWebp($responseHeaders, $url); if($jpegConverted) die($jpegConverted);
// Finally, output the content
echo file_get_contents($url);
///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
function checkWebp($headers, $url) {
//if its not webp image, return false
if(!isset($headers['Content-Type']) || $headers['Content-Type'] != 'image/webp') return false;
//for webp we need to convert it to jpg
$img = imagecreatefromwebp($url);
//output to var
ob_start();
imagejpeg($img, null, 60);
$content = ob_get_clean(); // Get the content of the output buffer
imagedestroy($img);
//remove old header and set new one
header_remove();
header_remove('Content-Type');
header('Content-Type: image/jpeg');
//add feader with filename of the downloaded file
//header('Content-Disposition: inline; filename="'.basename($url).'.jpg"');
header('Content-Disposition: inline; filename=photo.jpeg');
return $content;
}