Forum Moderators: coopster

Message Too Old, No Replies

Displaying blob images, headers already sent

         

tomhumf

4:31 pm on Aug 30, 2008 (gmt 0)

10+ Year Member



Hi,

[webmasterworld.com...]

I found this in the library, I guess you can't reply to it so I've started a new topic. I want to display blob images in the content of my website.

I can display blob images on their own page by setting the header to image/gif. When I use the code in my website I get the headers already sent message as the headers are originally set to text/html.

Is there a way of displaying many content types on one page? Or is the only way of overcoming this problem to use output buffering?

thanks
Tom

coopster

4:47 pm on Aug 30, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, tomhumf.

If you are trying to output many images using header() function over and over you are going to have issues. You need to set each <img> up in the HTML just as the example on that page shows.

cameraman

4:49 pm on Aug 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Look at the thread closely. The script that sends the image to the browser does only that, and is referenced in the html:

<img src="getblob.php">

So you may have a script generating the "parent" page, but then you have a different script (or call the same with parameters so that it can decide whether to generate parent or elements) for the image itself.

tomhumf

5:57 pm on Sep 2, 2008 (gmt 0)

10+ Year Member



thanks for your replies coopster and cameraman, I'm now able to display the blob images using that method. The images are for user profiles, I want to enable users to upload one image, if they upload another it just replaces the first. I have done this using something like:

$row = mysql_fetch_array(mysql_query("SELECT * FROM $my_table WHERE `username`='$username'"));

if($row){
mysql_query("DELETE from $my_table where `username`='$username'");
}

mysql_query("INSERT INTO $my_table (username,image) VALUES ('$username','".addslashes($new_image_data)."')");

But i'm concerned that by storing the username with the blob data I am defeating the point of using blobs in the first place. Does this seem like an o.k way of doing it? I have validated the image using a few different methods. It's a small site so I guess I may be worrying about security too much...