summaryrefslogtreecommitdiff
path: root/forum/utils/file.php
diff options
context:
space:
mode:
authordeva <deva>2008-10-12 17:00:54 +0000
committerdeva <deva>2008-10-12 17:00:54 +0000
commitbf738e366e34c330649a9f36a3b2001231230b3a (patch)
tree9ced926fe91f0dad3a75a0687b119439f898e6f6 /forum/utils/file.php
parent28856d6f9b7d726b1681df9384f3ef000dbf6f4c (diff)
Now the file preview on images are scaled down.
Diffstat (limited to 'forum/utils/file.php')
-rw-r--r--forum/utils/file.php32
1 files changed, 27 insertions, 5 deletions
diff --git a/forum/utils/file.php b/forum/utils/file.php
index 25cb4c2..b1f4e50 100644
--- a/forum/utils/file.php
+++ b/forum/utils/file.php
@@ -3,6 +3,7 @@
include_once("config.php");
include_once($UTIL_DIR . "/mimetypes.php");
include_once($UTIL_DIR . "/files.php");
+include_once($UTIL_DIR . "/imagecache.php");
function getFile($fid)
{
@@ -30,26 +31,47 @@ function getFile($fid)
function getFilePreview($fid)
{
- global $DATA_DIR, $PERMSTORE, $MIME_TYPES;
+ global $DATA_DIR, $UTIL_DIR, $PERMSTORE, $MIME_TYPES;
$files = new Files($DATA_DIR . "/files.xml");
$file = $files->getFile($fid);
$filename = $PERMSTORE . "/" . $file->fid;
- if(strstr($file->mimetype, "image")) {
+ if(strstr($file->mimetype, "image/")) {
header('Content-Description: File Transfer');
header('Content-Type: ' . $file->mimetype);
- header('Content-Length: ' . filesize($filename));
- header('Content-Disposition: inline; filename=' . basename($file->name));
- readfile($filename);
+
+ switch($file->mimetype) {
+ case "image/png":
+ $image = imagecreatefrompng($filename);
+ $image = rescale($image);
+ imagepng($image);
+ break;
+ case "image/jpeg":
+ $image = imagecreatefromjpeg($filename);
+ $image = rescale($image);
+ imagejpeg($image);
+ echo "@";
+ break;
+ case "image/gif":
+ $image = imagecreatefromgif($filename);
+ $image = rescale($image);
+ imagegif($image);
+ break;
+ }
+
+ imagedestroy($image);
} else {
+ header('Content-Description: File Transfer');
header("Content-type: image/png");
+
$im = @imagecreate(8 + strlen($file->name) * 5, 20)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, $file->name, $text_color);
imagepng($im);
+
imagedestroy($im);
}
}