-
Notifications
You must be signed in to change notification settings - Fork 28
/
img.php
59 lines (58 loc) · 2.61 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
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
|--------------------------------------------------------------------------|
| https://github.com/Bigjoos/ |
|--------------------------------------------------------------------------|
| Licence Info: GPL |
|--------------------------------------------------------------------------|
| Copyright (C) 2010 U-232 V4 |
|--------------------------------------------------------------------------|
| A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon. |
|--------------------------------------------------------------------------|
| Project Leaders: Mindless,putyn. |
|--------------------------------------------------------------------------|
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/ \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \
( U | - | 2 | 3 | 2 )-( S | o | u | r | c | e )-( C | o | d | e )
\_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
*/
// img.php by pdq 2011 =)
error_reporting(0);
/* Locate images folder outside of webroot */
define('BITBUCKET_DIR', DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'bucket'); // /path/to/bitbucket
/* Sanity checking */
function valid_path($root, $input)
{
$fullpath = $root . $input;
$fullpath = realpath($fullpath);
$root = realpath($root);
$rl = strlen($root);
return ($root != substr($fullpath, 0, $rl)) ? NULL : $fullpath;
}
/* Process request */
if (isset($_SERVER['REQUEST_URI'])) {
$image = valid_path(BITBUCKET_DIR, substr($_SERVER['REQUEST_URI'], strlen($_SERVER['SCRIPT_NAME'])));
if (!((($pi = pathinfo($image)) && preg_match('#^(jpg|jpeg|gif|png)$#i', $pi['extension'])) && $image && is_file($image))) die('^_^');
$img['last_mod'] = filemtime($image);
$img['date_fmt'] = 'D, d M Y H:i:s T';
$img['lm_date'] = date($img['date_fmt'], $img['last_mod']);
$img['ex_date'] = date($img['date_fmt'], time() + (86400 * 7));
$img['stop'] = false;
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
$img['since'] = explode(';', $_SERVER['HTTP_IF_MODIFIED_SINCE'], 2);
$img['since'] = strtotime($img['since'][0]);
if ($img['since'] == $img['last_mod']) {
header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
$img['stop'] = true;
}
}
header('Expires: ' . $img['ex_date']);
header('Cache-Control: private, max-age=604800');
if ($img['stop']) die();
header('Last-Modified: ' . $img['lm_date']);
header('Content-type: image/' . $pi['extension']);
readfile($image);
exit();
}
// End of File
?>