-
Notifications
You must be signed in to change notification settings - Fork 10
/
img.php
52 lines (51 loc) · 1.93 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
<?php
/**
* ------- U-232 Codename Trinity ----------*
* ---------------------------------------------*
* -------- @authors U-232 Team --------------*
* ---------------------------------------------*
* ----- @site https://u-232.duckdns.org/ ----*
* ---------------------------------------------*
* ----- @copyright 2020 U-232 Team ----------*
* ---------------------------------------------*
* ------------ @version V6 ------------------*
*/
require_once(__DIR__.DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'bittorrent.php');
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();
}
?>