Displaying an image from a database...
Posted by: Cobra
Posted on: 2007-11-07 21:37:00
I wrote a script that displays images that are stored in a database. It worked properly for one table of images, but now it doesn't. Instead of the page displaying the image, I get "Resource id #11." I searched the internet and found out that its not an error message. I didn't find out what it actually means, though.
This is the script:
if(isset($id))
{
$sql= mysql_query("SELECT * FROM `image` WHERE `image_id` = '$id'");
if(mysql_num_rows($sql) != 0)
{
$row = mysql_fetch_assoc($sql) or die(mysql_error());
$image_type = $row['image_type'];
$image = $row['image'];
header("Content-type: $image_type");
echo $image;
}
else echo "Invalid image ID";
}
The table contains image_id (varchar), image_type (varchar), and image (longblob). Any ideas?