Jump to content

retrieving BLOB fields


danrah

Recommended Posts

you can not directly display images stored in a db in a web page like that.  what you have to do is put an image tag like this in the web page:
[code]<img src="getimage.php?id=????">[/code]
the ???? part above would be replaced by the primary key of the row # in the db that the image is stored in.  If you need to determine that at run time, then you have to code it like this:
[code]<img src="getimage.php?id=<?php echo $rownum; ?>">[/code]
--notice the php code nested in the img tag.  $rownum would have to be set somewhere above in the code.
--the getimage.php contains code that gets the url passed rownum, opens the db, retrieves the correct row, then does this:
[code]header("Content-type:  image/jpeg");
echo $dbimagefield; //now we echo it[/code]
--getimage.php must not output anything except the 2 statements above, even a single excess space before the opening php start tags in that code will cause it to fail.

--If you store graphics right in the db itself, you have to go through all kinds of extra hoops to display them on a web page.  As well, all the extra hits on the db will slow down the page.  That's why it's almost always better to store just the file name of the graphic in the db, and store the graphic as just a normal graphic on the server.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.