Skip to content

Commit

Permalink
Added header for file name
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiebicknell committed Jul 10, 2014
1 parent 626de87 commit 474d702
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions thumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@
die('File is not an image');
}

$file_salt = 'v1.0.2';
$file_salt = 'v1.0.3';
$file_size = filesize($src);
$file_time = filemtime($src);
$file_date = gmdate('D, d M Y H:i:s T', $file_time);
$file_type = strtolower(substr(strrchr($src, '.'), 1));
$file_hash = md5($file_salt . ($src.$size.$crop.$trim.$zoom.$align.$sharpen.$gray.$ignore) . $file_time);
$file_name = THUMB_CACHE . $file_hash . '.img.txt';
$file_temp = THUMB_CACHE . $file_hash . '.img.txt';
$file_name = basename(substr($src, 0, strrpos($src, '.')) . strtolower(strrchr($src, '.')));

if (!file_exists(THUMB_CACHE . 'index.html')) {
touch(THUMB_CACHE . 'index.html');
Expand Down Expand Up @@ -97,13 +98,14 @@
}
}

if (!file_exists($file_name)) {
if (!file_exists($file_temp)) {
list($w0, $h0, $type) = getimagesize($src);
$data = file_get_contents($src);
if ($ignore && $type == 1) {
if (preg_match('/\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)/s', $data)) {
header('Content-Type: image/gif');
header('Content-Length: ' . $file_size);
header('Content-Disposition: inline; filename="' . $file_name . '"');
header('Last-Modified: ' . $file_date);
header('ETag: ' . $file_hash);
header('Accept-Ranges: none');
Expand Down Expand Up @@ -229,7 +231,7 @@
if ($gray) {
imagefilter($im, IMG_FILTER_GRAYSCALE);
}
imagegif($im, $file_name);
imagegif($im, $file_temp);
break;
case 2:
imagecopyresampled($im, $oi, $x, $y, 0, 0, $w1, $h1, $w0, $h0);
Expand All @@ -239,7 +241,7 @@
if ($gray) {
imagefilter($im, IMG_FILTER_GRAYSCALE);
}
imagejpeg($im, $file_name, 100);
imagejpeg($im, $file_temp, 100);
break;
case 3:
imagefill($im, 0, 0, imagecolorallocatealpha($im, 0, 0, 0, 127));
Expand All @@ -254,15 +256,16 @@
if ($gray) {
imagefilter($im, IMG_FILTER_GRAYSCALE);
}
imagepng($im, $file_name);
imagepng($im, $file_temp);
break;
}
imagedestroy($im);
imagedestroy($oi);
}

header('Content-Type: image/' . $file_type);
header('Content-Length: ' . filesize($file_name));
header('Content-Length: ' . filesize($file_temp));
header('Content-Disposition: inline; filename="' . $file_name . '"');
header('Last-Modified: ' . $file_date);
header('ETag: ' . $file_hash);
header('Accept-Ranges: none');
Expand All @@ -275,4 +278,4 @@
header('Pragma: no-cache');
}

readfile($file_name);
readfile($file_temp);

0 comments on commit 474d702

Please sign in to comment.