I was just wondering what the PHP code is to echo an image I've stored in a particular table of my database.
Asked
Active
Viewed 3,726 times
3 Answers
2
Well, here is the html you want for the image:
<img src="image_render.php?image_id=4" /> <!-- or any unique identifier for that image -->
in image_render.php
you will want to do the following:
// get the image information base on the unique identifier passed in the URL
header("Content-Type: image/png"); // tell the browser that this is an image
echo $imageBlog; // this is what you took from the database
Make sure you don't add extra output in this file, or things will go bad.
That's about it.
Note
In most situations it is better/faster to simply store the image location on the server instead of the whole image, so you probably need to document yourself a bit more before making this decision.
Here is a discussion about the advantages and disadvantages of storing images in the database, and another one here.
Good luck!

Community
- 1
- 1

Vlad Preda
- 9,780
- 7
- 36
- 63
0
I hope echo html_entity_decode($blobfield) will help you to write image if it is uploaded using any editor.

aishazafar
- 1,024
- 3
- 15
- 35
0
According to another answer on a similar topic here on SO,
echo "<dt><strong>Technician Image:</strong></dt><dd>" .
'<img src="data:image/jpeg;base64,'.
base64_encode($row2['image']).
'" width="290" height="290">' . "</dd>";
*Do try to search before posting.