[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

Issue with header() and display jpeg

Hi all,

I try to display a jpeg image with the following command :
header("Content-Type: image/jpeg");

But it raises the following error (sorry it's in french) :
L'image « http://localhost/redim2.php?image=3 » ne peut être affichée, car elle contient des erreurs.

If I comment the instruction header(), the image is displayed with a lot of strange characters but it's displayed.

So what i have to change to make it works ?

TIA
0
Richard Coffre
Asked:
Richard Coffre
  • 2
1 Solution
 
hernst42Commented:
Make sure you don't have any trailing ouput (special white-spaces ..). Search for that output and eleminate that output

try this:
<?php ob_start();
?>Your code<?php
header("Content-Type: image/jpeg");
ob_clean();

// create/show image-code
0
 
_GeG_Commented:
I think that your code produces extra characters that mess up the picture. Do you send debugging messages?
or does it look like:
____________


<?php
...
?>
____________

notice the blanks above the <?php. They will make php send an error about headers that cannot be sent, so your image will not be recognized.
remove all whitespace before the <?php
0
 
_GeG_Commented:
I must learn to type faster ;)
0
 
gruntarCommented:
Header is fine. Error says that image has errors and can't be shown. Can you show the code to display image?
Cheers
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now