-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththumbnail.php
72 lines (60 loc) · 2.25 KB
/
thumbnail.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
<?php
$currDir=dirname(__FILE__);
include("$currDir/defaultLang.php");
include("$currDir/language.php");
include("$currDir/lib.php");
handle_maintenance();
// image paths
$p=array(
);
if(!count($p)) exit;
// receive user input
$t = $_GET['t']; // table name
$f = $_GET['f']; // field name
$v = $_GET['v']; // thumbnail view type: 'tv' or 'dv'
$i = $_GET['i']; // original image file name
// validate input
if(!in_array($t, array_keys($p))) getImage();
if(!in_array($f, array_keys($p[$t]))) getImage();
if(!preg_match('/^[a-z0-9_-]+\.(gif|png|jpg|jpeg|jpe)$/i', $i, $m)) getImage();
if($v != 'tv' && $v != 'dv') getImage();
if($i == 'blank.gif') getImage();
$img=$p[$t][$f].$i;
$thumb=str_replace(".$m[1]ffffgggg", "_$v.$m[1]", $img.'ffffgggg');
// if thumbnail exists and the user is not admin, output it without rebuilding the thumbnail
if(getImage($thumb) && !getLoggedAdmin()) exit;
// otherwise, try to create the thumbnail and output it
if(!createThumbnail($img, getThumbnailSpecs($t, $f, $v))) getImage();
if(!getImage($thumb)) getImage();
function getImage($img = '') {
if(!$img) { // default image to return
$img = './photo.gif';
$exit = true;
}
/* force caching */
$last_modified = filemtime($img);
$last_modified_gmt = gmdate('D, d M Y H:i:s', $last_modified) . ' GMT';
$expires_gmt = gmdate('D, d M Y H:i:s', $last_modified + 864000) . ' GMT';
$headers = (function_exists('getallheaders') ? getallheaders() : $_SERVER);
if(isset($headers['If-Modified-Since']) && (strtotime($headers['If-Modified-Since']) == $last_modified)) {
@header("Last-Modified: {$last_modified_gmt}", true, 304);
@header("Cache-Control: private, max-age=864000", true);
@header("Expires: {$expires_gmt}");
exit;
}
$thumbInfo = @getimagesize($img);
$fp = @fopen($img, 'rb');
if($thumbInfo && $fp) {
$file_size = filesize($img);
@header("Last-Modified: {$last_modified_gmt}", true, 200);
@header("Pragma:");
@header("Cache-Control: private, max-age=864000", true);
@header("Content-type: {$thumbInfo['mime']}");
@header("Content-Length: {$file_size}");
@header("Expires: {$expires_gmt}");
ob_end_clean();
@fpassthru($fp);
if(!$exit) return true; else exit;
}
if(!$exit) return false; else exit;
}