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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

header problem 1

Status
Not open for further replies.

sarbruis

Programmer
Aug 19, 2004
5
US
i'm trying to get an image to appear, so i did:

header("Content-type: image/jpg");
imagejpeg($image);

I get the following error: Warning: Cannot modify header information - headers already sent by (output started at C:\Documents and Settings\Owner\Desktop\PHP Files, etc\-:13) in C:\Documents and Settings\Owner\Desktop\PHP Files, etc\- on line 24

thanks for any help. BTW, i solved my GD library problem.
 
Code:
?

hint.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
if you mean <?php ?>, I did that; I was just showing the code segment I used the header in.
 
when using headers youould make sure that nothing else prints out to the screen before the header() function. check for echo() commands and errors.
 
Not only echo commands and error:
Any additional white space before the <? change of context is sent to the browser. So, you can't have the script you have embedded in a HTML page where you want the image to appear - that will not work.
If you want to do that you will have to write a small script which supplies the image data (excatly with the headers you have) as a separate request. The browser will fetch the image data by interpreting the 'src' attribute of the img tag.
Code:
# WRONG - won't work
<td>
<? 
header("Content-type: image/jpg");
imagejpeg($image);
....
# RIGHT
<td>
<img src="fetchimg.php?image=whatever>
</td>

# with a scriptfetchimg.php
<?
header("Content-type: image/jpg");
imagejpeg($_GET['image']);
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top