1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,51 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+$file = base64_decode($_GET['file']); |
|
4 |
+ |
|
5 |
+$url = $file; |
|
6 |
+ |
|
7 |
+$auth = false; |
|
8 |
+ |
|
9 |
+if(isset($_GET['debug'])) { |
|
10 |
+ echo "####### IMG URL #######\n"; |
|
11 |
+ echo $file."\n"; |
|
12 |
+} |
|
13 |
+if (in_array("@", str_split($file))) { |
|
14 |
+ $auth = TRUE; |
|
15 |
+ if(isset($_GET['debug'])) { |
|
16 |
+ echo "AUTH DETECTED!\n"; |
|
17 |
+ echo "CREDS: ".str_replace(array("http://", "https://"), "", explode("@", $url)[0])."\n"; |
|
18 |
+ echo "URL: ".explode(":", $url)[0]."://".explode("@", $url)[1]."\n"; |
|
19 |
+ } |
|
20 |
+} |
|
21 |
+ |
|
22 |
+ |
|
23 |
+$cache_file = './data/'.str_replace("=", "", base64_encode($file)); |
|
24 |
+ |
|
25 |
+if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 60 * 2 ))) { |
|
26 |
+ $file = file_get_contents($cache_file); |
|
27 |
+} else { |
|
28 |
+ if($auth) { |
|
29 |
+ $authpass = base64_encode(str_replace(array("http://", "https://"), "", explode("@", $url)[0])); |
|
30 |
+ $context = stream_context_create([ |
|
31 |
+ "http" => [ |
|
32 |
+ "header" => "Authorization: Basic $authpass" |
|
33 |
+ ] |
|
34 |
+ ]); |
|
35 |
+ $file = file_get_contents(explode(":", $url)[0]."://".explode("@", $url)[1], false, $context ); |
|
36 |
+ } else { |
|
37 |
+ $file = file_get_contents($url); |
|
38 |
+ } |
|
39 |
+ if(strlen($file) < 300) { |
|
40 |
+ if (file_exists($cache_file)) { |
|
41 |
+ $file = file_get_contents($cache_file); |
|
42 |
+ } else { |
|
43 |
+ die("Please try again later"); |
|
44 |
+ } |
|
45 |
+ } else { |
|
46 |
+ file_put_contents($cache_file, $file, LOCK_EX); |
|
47 |
+ } |
|
48 |
+} |
|
49 |
+if(!isset($_GET['debug'])) { header('Content-Type: image/png'); } else { echo "####### IMG DATA #######\n"; } |
|
50 |
+ |
|
51 |
+echo $file; |