Forum Moderators: coopster

Message Too Old, No Replies

How to display images stored in DB

HOw?

         

Grenz

9:13 am on Apr 17, 2009 (gmt 0)

10+ Year Member



Hi
I have uploaded images to my DB and saved the images as longblobs.

Now I want to display the images on my page using:

header ("content-type: image/jpg");
ECHO $imagefile

The result is a print of the code and no image: logo-9ee9e10df14c51c9827fbd5f04c381791239958344.jpg

Im very new to php - any help appreciated.

Thanks in advance

HelenDev

10:16 am on Apr 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there any particular reason you want to actually store the images in the database?

The way I usually do it is that I have the images uploaded to a directory on the server somewhere, for example with a unique name like image247.jpg. Then just put a text(varchar) column in the database, which simply contains 'image247.jpg'. Or you could even use the 'id' column to generate the image name and you wouldn't need an extra field for it.

Then when it comes to build the page I just use the reference to point to wherever it is on the server.

Grenz

11:36 am on Apr 17, 2009 (gmt 0)

10+ Year Member



Sorry - I should have explained in more detail.
Each image in the database is a part of a datarow which again is a part of a search function.

So some user fill in a form and upload an image file - then othe users are able to search in the DB and the results returned are text, dates, images etc.

The output echo is displayed in a table.
All the text, dates etc. will output nicely - but instead of showing an image - the filename is displayed.

tomhumf

12:12 pm on Apr 20, 2009 (gmt 0)

10+ Year Member



Have a look at this [webmasterworld.com...]