开发者

What's the all fit header to show images?

开发者 https://www.devze.com 2022-12-10 02:30 出处:网络
header(\"Content-type:i开发者_如何学编程mage/gif\"); readfile($filename); The above can only be used to show gif images.
header("Content-type:   i开发者_如何学编程mage/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?


This should work for all image types:

$size = getimagesize($filename);

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


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

OR

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

OR

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


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消