CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Header("Content-type: image/jpeg"); problem (http://www.codingforums.com/showthread.php?t=275751)

Drunklord 10-08-2012 03:58 PM

Header("Content-type: image/jpeg"); problem
 
Hi all! Using PHP 5.3.1 con Apache 2.2.21 I can not run this

Code:

<!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>

The error message indicates: “can not show the image http://localhost/clipped_image.php , it contains errors”
When I borrow this line

Code:

Header("Content-type: image/jpeg");
The page shows char equivalent of the image file's bytes. So, I think that putting in Header("Content-type: image/jpeg"); creates a problem, but why?

Anyone can help me, please?

tangoforce 10-08-2012 05:05 PM

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.


All times are GMT +1. The time now is 06:11 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.