From 28856d6f9b7d726b1681df9384f3ef000dbf6f4c Mon Sep 17 00:00:00 2001 From: deva Date: Sun, 12 Oct 2008 16:02:03 +0000 Subject: Made file preview (original image or png with filename as text). Added error image as png with error text. --- forum/utils/file.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'forum/utils/file.php') diff --git a/forum/utils/file.php b/forum/utils/file.php index 50993b5..25cb4c2 100644 --- a/forum/utils/file.php +++ b/forum/utils/file.php @@ -28,4 +28,30 @@ function getFile($fid) readfile($filename); } +function getFilePreview($fid) +{ + global $DATA_DIR, $PERMSTORE, $MIME_TYPES; + $files = new Files($DATA_DIR . "/files.xml"); + $file = $files->getFile($fid); + + $filename = $PERMSTORE . "/" . $file->fid; + + 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); + } else { + 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); + } +} + ?> \ No newline at end of file -- cgit v1.2.3