Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Put blob image into html code

Status
Not open for further replies.

andreNS

Programmer
Jul 5, 2004
3
PT
Hello,

I'm storing images in a mysql mediumblob field, and now I'm trying to download it into the html code.

My problem is that I receive the message "Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\GeStand\index.php:129) in C:\Program Files\Apache Group\Apache2\htdocs\GeStand\index.php on line 110"

I try to change the content type to show the image...

CODE:

function getImage()
...
header("Content-Type: ".$image_type);
$image = $row['image'];
return $image;
...

HTML code where I'm trying to display the image
...
<tr>
<td>
<img src=<?php echo(getImagem()); ?>>
</td>
</tr>
...

I spend 2 days trying to solve this problem... somebody help me please!

Sorry my English.
Thanks in advance.

André.
 
Your problem is that you're trying to send both the image data and the HTML of the page in the same connection.

When a web browser connects to a web server, it can only fetch one type of content. Generally, the browser will fetch the HTML of a page and any images on that page (in "<IMG>" tags) as separate connections.

You will need two scripts: one to output the HTML, the other to output the image.


For information on your error, see my FAQ in this forum: faq434-2999



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Headers need to be sent before anything else -> so if you even have a stray space char or something like that before the header is sent you will receive that message.
 
you have already sent down headers to the client and you can't send new ones to specify the image headers. This is main problem behind the storing of images in the db.

The trick here is to have a page that does nothing but get and ouput the image

like:
Code:
...
header("Content-Type: ".$image_type);
$image = $row['image'];
...

and the regular page where you are tryng to display the image goes like this:
Code:
...
<tr>
 <td>
   <img src="/path/to/file/nam.php?image_id=someimageid">
 </td>
</tr>
...



Bastien

Cat, the other other white meat
 
Bastien,

Using your sugestion I must download image from hard disk?

Thanks.
 
well, since the image is in the db, yes...

Bastien

Cat, the other other white meat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top