-
Notifications
You must be signed in to change notification settings - Fork 1
/
getImage.php
73 lines (58 loc) · 1.45 KB
/
getImage.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* gets a file via HTTP and returns the response.
* in your face, same origin policy!
*/
/**
* 1048576 == 1MB
*/
function file_get_contents2($url, $header = array(), $maxlength = 1048576) {
$urlbits = parse_url($url);
$readlength = 0;
$result = '';
$fp = fsockopen($urlbits['host'], 80, $errno, $errstr, 10);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
$failcount++;
//logmessage("FAIL... ", 2, false);
return false;
} else {
$out = "GET " . $urlbits['path'] . '?' . $urlbits['query'] . " HTTP/1.1\r\n";
$out .= "Host: ".$urlbits['host']."\r\n";
foreach($header as $headerkey => $headerval) {
$out .= $headerkey . ": " . $headerval . "\r\n";
}
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp) && ($readlength < $maxlength)) {
$result .= fgets($fp, 128);
$readlength += 128;
}
if ($readlength > $maxlength) {
throw new Exception('zu groß');
}
//logmessage((getmicrotime()-$start_request)."\n", 2, false);
fclose($fp);
}
return $result;
}
if (!isset($_GET['url'])) {
exit();
}
if (substr($_GET['url'], 0, 7) !== 'http://') {
exit('nope.');
}
$url = $_GET['url'];
try {
$file = file_get_contents2($url);
} catch(Exception $e) {
exit('error!');
}
$start = strpos($file, "\r\n\r\n");
$header = substr($file, 0, $start);
$header = explode("\r\n", $header);
header('Content-type: text/plain');
foreach ($header as $headerfield) {
header($headerfield);
}
echo substr($file, $start + 4);