View Full Version : include and readfile wont show gif file as image
gorilla1
09-22-2002, 05:47 PM
I am attempting to open files in a directory for display, and it works fine, with the exception of gif files (which happen to be the ones that I really want to display). I have tried both readfile and include, as follows:
readfile($thisFile[0]);
include($thisFile[0]);
Both display the gif file as a jumble of ascii charactrers. What's extra bizarre is that I know this was working at one point using the include.... I am getting the same result under phpdev or on a server.
Anyone have a clue where I am going astray?
G
firepages
09-23-2002, 09:06 AM
justaguess::try adding the content type.. ??
<?
echo header("Content-Type: image/gif");
readfile($thisFile[0]);
?>
Alekz
09-23-2002, 09:50 AM
Hi, here's the code You need in case the image file is loaded from a BLOB field in a mySQL table. You can replace querying the databse with a simple fread() ...
$query = "SELECT * FROM files WHERE file_id = " . (integer)$file_id;
$result = mysql_query($query);
if ($result){
if (mysql_num_rows($result)>0){
if($array=mysql_fetch_array ($result)){
$content = $array["content"];
$filename = $array["file_name"];
$file_size = $array["file_size"];
$file_ext = ExtractFileExtention($filename);
switch($file_ext){
case "gif":
header("Content-Type: image/gif");
break;
case "jpg":
header("Content-Type: image/jpeg");
break;
case "jpeg":
header("Content-Type: image/jpeg");
break;
case "bmp":
header("Content-Type: image/bmp");
break;
case "rm":
header("Content-Type: audio/x-pn-realaudio");
break;
default:
header("Content-Type: */*");
break;
}
header("Content-Length: " . $file_size);
header("Content-Disposition: inline;filename=" . $filename);
print($content);
}
}
}
Alex
gorilla1
09-23-2002, 02:13 PM
Ah, thanks, firepages and Alekz!
G
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.