forked from RomanSixty/Feed-on-Feeds
-
Notifications
You must be signed in to change notification settings - Fork 3
/
img.php
48 lines (39 loc) · 1.08 KB
/
img.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
<?php
// Image proxy for FeedOnFeeds, to assist with hotlinking and security policy issues
require_once 'fof-main.php';
$item_id = $_GET['item'];
if (!$item_id) {
die("Missing item ID");
}
$url = $_GET['url'];
if (!$url) {
die("Missing URL");
}
// TODO: make sure we're logged in
$item = fof_get_item(NULL, $item_id, false);
if (!$item) {
die("couldn't get item");
}
// fix relative URLs with $item['item_link']
$url = urljoin($item['item_link'], $url);
function dump_headers($ch, $header) {
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
if (($http_code < 300 || $http_code >= 400) && strpos($header, ':')) {
fof_log("image $url header: $header");
header(rtrim($header));
}
return strlen($header);
}
$curl = curl_init($url);
curl_setopt_array($curl, array(
CURLOPT_REFERER => $item['item_link'],
CURLOPT_HEADERFUNCTION => 'dump_headers',
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_AUTOREFERER => true,
CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
));
curl_exec($curl);
fof_log(curl_error($curl));
curl_close($curl);
?>