Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
10-08-2012, 03:58 PM #1
- Join Date
- Sep 2011
- Thanked 0 Times in 0 Posts
Header("Content-type: image/jpeg"); problem
Hi all! Using PHP 5.3.1 con Apache 2.2.21 I can not run this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" <head> <title>Draw image with gd</title> </head> <body> <?php Header("Content-type: image/jpeg"); $im = @imagecreatefromjpeg(“myImage”); Imagejpeg($im); ImageDestroy($im); ?> </body> </html>
When I borrow this line
Anyone can help me, please?
10-08-2012, 05:05 PM #2
- Join Date
- Feb 2011
- Your Monitor
- Thanked 530 Times in 517 Posts
It's really rather obvious when you think about it. Your jpeg file would not normally comtain any html would it? just jpeg file data.
With that being the case, why are you printing the file into your html? - how will the browser know that it is supposed to be displayed as an image?
Every time a browser disp;ays a webpage it reads the source for <img> tags and downloads the file from the server seperately. That is where php should be using this header and outputting the file stream, in a seperate php file addressed in the img tag.
See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/
Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!