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

  • 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 ?

Richard Coffre
Richard Coffre
  • 2
1 Solution
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");

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


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
I must learn to type faster ;)
Header is fine. Error says that image has errors and can't be shown. Can you show the code to display image?

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