29

I have an image, but it keep doesn't display. I check the image properties (right-click and chose properties), and the I found the "type" is text/html not JPEG image. Is this because the type that cause my images dont show up?? How to change the "Type" value? I am using php...

I display the image in a simple html [img] tag...

EDIT:

Yeah, i tried.. If i include the

<?php header('Content-Type:image/jpeg'); ?>

It display the URL, very weird huh??

I am using apache, the image is generated by php code...

<img src="<?php echo bloginfo('template_url'); ?>/thumb.php?src=<?php echo get_post_meta($post->ID, "image", $single = true); ?>&amp;h=195&amp;w=540&amp;zc=1&amp;q=95" alt="<?php the_title(); ?>
miken32
  • 42,008
  • 16
  • 111
  • 154
  • You don't mention which webserver you are using. Also, is the image you are displaying a normal file on the webserver, or is it a generated image, also using PHP? Is it only this one image that doesn't work, or does it happen for all images hosted on this server? – Andre Miller May 28 '09 at 07:29
  • Call the image URL directly with your browser and see if you get an error. If your browser reports that the image is broken, there is an error in your image generation code but the header() is fine. I am pretty sure that your content type is correctly set now. The error is probably somewhere else. – Lennart Koopmann May 28 '09 at 07:33
  • Called, C:/wamp/www/wp-content/uploads/2009/05/1.jpg not found. BUT, the image file is in that folder. Weird huh?? –  May 28 '09 at 07:40
  • I test it locally, using wamp, its wordpress thing... –  May 28 '09 at 07:42
  • Does this answer your question? [change mime type of output in php](https://stackoverflow.com/questions/152006/change-mime-type-of-output-in-php) – miken32 Sep 24 '20 at 17:36

2 Answers2

49
header('Content-Type: image/jpeg');

Make sure to call the header() function before doing any output or you will get a "Headers already sent" error.

Lennart Koopmann
  • 20,313
  • 4
  • 26
  • 33
3

Sounds like the image was generated by some kind of server-side script. If it was generated by a PHP script that you have access to, just include a call to header(), like this:

header('Content-Type: image/jpeg');

Make sure to call header() before outputting anything—even a blank line or stray space that was accidentally output will cause header() to fail (usually it's best if you put your call to header() at the beginning of the script).

If you don't have access to the script that generated the image, then you're out of luck, I think.

hbw
  • 15,560
  • 6
  • 51
  • 58