another
another

Reputation: 117

What's the all fit header to show images?

header("Content-type:   image/gif");  
readfile($filename);   

The above can only be used to show gif images.

Is there a header that can be used to show jpg/png/gif?

Upvotes: 2

Views: 1139

Answers (3)

Alix Axel
Alix Axel

Reputation: 154553

This should work for all image types:

$size = getimagesize($filename);

header('Content-type: ' . $size['mime']);
readfile($filename);

Upvotes: 4

jitter
jitter

Reputation: 54605

header("Content-type:   image/gif");

OR

header("Content-type:   image/jpeg");

OR

header("Content-type:   image/png");

Upvotes: 4

ceejayoz
ceejayoz

Reputation: 180023

You need to know or figure out what type of file it is, and send the proper type. There's no catch-all content type for images that'll work for GIF, PNG, and JPEG all at once.

finfo_file() will let you detect the type of an image (or any other file).

Upvotes: 3

Related Questions