-
Notifications
You must be signed in to change notification settings - Fork 0
/
thumbnail.php
52 lines (41 loc) · 1.36 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
<?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();
$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;
}
$thumbInfo=@getimagesize($img);
$fp=@fopen($img, 'rb');
if($thumbInfo && $fp){
header("Content-type: {$thumbInfo['mime']}");
fpassthru($fp);
if(!$exit) return TRUE; else exit;
}
if(!$exit) return FALSE; else exit;
}