hi guys,
My project is based on online shopping
so admin is the of the users of our s/w
we want to provide an option of storing images of newly introduced products
along with all details through a form..
and when customer logs in he should be able to view the details(along with the image)..

so all i need is a code snippet to store n retrieve image from database using php..

pls help me out..!!:S

7 Years
Discussion Span
Last Post by smantscheff

If your raw image data are stored in a database, you need a script which not only retrieves them but also adds the html image headers. For example with JPEG images, you might code something like this:

your database connector retrieves image data as $imgdata
with a query like "select imgdata from images where id='$myId'" 

header( "Content-type: image/jpeg" );
echo $imgdata;

[No closing ?> bracket at the end - more often than not you'll overlook a blank at the end of the file]

If this script is called myimage.php, you can use it as an image file name in html: <img src='myimage.php?id=xyz' />


You have to store the location of the image in your DB.
Eg. "../images/image.jpg"

and use it with

<img src="<?=$image?>">

@javvy: You are assuming that images are external files. This is not necessarily so, and there are many good reasons to store them in the database.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.