Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-08-2012, 03:58 PM   PM User | #1
Drunklord
New Coder

 
Join Date: Sep 2011
Posts: 27
Thanks: 8
Thanked 0 Times in 0 Posts
Drunklord is an unknown quantity at this point
Question 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?
Drunklord is offline   Reply With Quote
Old 10-08-2012, 05:05 PM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,519
Thanks: 45
Thanked 440 Times in 429 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:15 PM.


Advertisement
Log in to turn off these ads.