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:
<?php
...
print "<img src='" . $row["image"] . "' alt='test' width='128' height='128' />"

...
?>

How can I display the image in the database?

My thanks in advanced

Recommended Answers

All 2 Replies

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.

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.