Forum Moderators: coopster

Message Too Old, No Replies

Content-type: image/gif (or /jpg or /png) not working.

having trouble with displaying an image saved in a db to the browser

         

kfancy

8:38 pm on Aug 5, 2006 (gmt 0)

10+ Year Member



Hi WebmasterWorld,

I'm having a seriously difficult time trying to get to the bottom of why I can't serve an image that I have saved in a database. I'm using a regular HTML form to upload the image, then grabbing the data and saving it to db (BLOB type)... retrieval generally works like:

/*
get image data info, save to array $d
*/
Header("Content-Type: image/gif");
echo $d["image_content"]; // image data from db

This results in:
The image "<SCRIPT NAME>" cannot be displayed, because it contains errors.

This approach has worked many times for me in the past, but for some reason (on a new client's server) it's not working. Server is running Apache 1.3.34 and PHP 5.1.2.

Just a note, I am able to read the info from the db, save it to an external file with appropriate suffix (i.e., ".gif" for a Gif89a), and then point the browser to it and it displays fine.... it seems to me something is wrong with how the server is parsing or accepting the header, but I can't find any documentation on a possible fix.

Any clues anyone?

\\ Kent

henry0

9:55 pm on Aug 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome Kfancy to WebmasterWorld!

I am wondering if the header comes on the very top of the script or is somewhere located in your script
Reason is:
Your previous server might have allowed
via "output buffering on" any header to be served from any positon in the script
if output buffering is: off then your header must be served before exec of any HTML or PHP

This can be fixed by changing your PHP.ini to allow output buffering.