Page 1 of 1

how to display images from the database

Posted: Wed Mar 31, 2004 6:09 am
by davidklonski
Hi

I have read the article in CodeWalkers about how to store and retrieve images from the database.

The article explains that once I have the type of the image and the image itself, then I can display them like this:

Code: Select all

Header ("Content-type: $image_type");
print $image;
I would like to be able to display the image within HTML content. Meaning that instead of writing:
...<img src="xxx.jpg"></img>...
I would display that image in that place. Note that the <img> tage may be embedded inside a much more complex html code.

does anyone know how I can make that last move?

thanks in advance

Posted: Wed Mar 31, 2004 6:53 am
by kettle_drum
Grab the image from the database and store it as a tmp file, and then just include it with <img>, or you could save the image as a file on your server instead of in the database - and just hold the location in the database.

Posted: Wed Mar 31, 2004 6:55 am
by markl999
You could also do <img src="genimage.php?id=4"> where genimage.php would use $_GET['id'] to grab the image from the db and output the appropriate header (as you have above). But storing the path/image name in the db is a better option imho. Better to keep binary data on the file system.