Hi I have some problems displaying images from MySQL to HTML page:
So I did the following thing:
CREATE TABLE Images (
PicNum int NOT NULL AUTO_INCREMENT PRIMARY
KEY,
Image BLOB
);
I am able to upload images into my database but but I am not
able to display them (you get the 'broken image'--seems like the image is loaded properly into the page) I don't know why.
-------------------test1.php---------------------------------
<?
.........
..........
$result=mysql_query("SELECT * FROM Images")
or die("Can't Perform Query");
While($row=mysql_fetch_object($result)) {
echo "<IMG SRC=\"test2.php?PicNum=$row->PicNum\">";
}
?>
-------------------test2.php-------------------------------
<?
........
......
$result=mysql_query("SELECT * FROM Images WHERE
PicNum=$PicNum") or die("Can't perform Query");
$row=mysql_fetch_object($result);
Header( "Content-type: image/gif");
echo $row->Image;
?>
Why I always see the 'broken image'?
Something wrong with the scripts?
Or is there any alternatif way to retrieve the picture from database?
Is it possible to rename the image file being stored into the database?
Thanks for any help to this!!!
P/S: I did include these in my upload script:
--------------upload.php----------------------------
If($Picture != "none") {
$PSize = filesize($Picture);
$mysqlPicture = addslashes(fread(fopen($Picture, "rb"), $PSize));
........insert picture into database.......
..........
....