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).
精彩评论