When I save an image into the database, the image field has the following information in the field:
<Binary Data>
But when I read the image from the database I get a "X" or a number like "4172726179" and the image is not displayed.
I'm using this code for displaying the image:
print "<img src='" . $row["image"] . "' alt='test' width='128' height='128' />"


How can I display the image in the database?

My thanks in advanced

2 Years
Discussion Span
Last Post by pixelsoul

When you're outputing images that are stored in the database you need to declare a header that tells the browser that the content is an image so it knows how to handle it. On the page where your query is for the image, you'll want to declare a header for a image format, for example:

header('Content-type: image/jpg');
     echo $row["image"];

I personally don't like storing images in a database, unless I had a specific reasoning, maybe to work around some issue.

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.