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

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:

<?php
[...
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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.