I made a small program for uploading pictures some time ago, but today someone said that jpg pictures cannot be uploaded. I tested it in local Chrome and Firefox and found that there was no problem and the upload was normal. I asked him what browser he was using, and it turned out to be Window of the World, and 360... I was embarrassed. I wonder if it's a problem with IE? So I tested it under IE, and sure enough it didn't work. The original procedure is as follows:
switch($type) { case "image/jpeg": $resultImage = imagecreatefromjpeg($original); imagejpeg($resultImage, $target, $quality); break; case "image/png": $resultImage = imagecreatefrompng($original); imagepng($resultImage, $target, $quality_png); break; case "image/gif": $resultImage = imagecreatefromgif($original); imagegif($resultImage, $target, $quality); break; default : die("不支持此文件类型"); exit; }
Later, I googled and found that there are indeed some differences in jpg format images under IE.
Upload a jpg image under IE, and then print the information of the uploaded file as follows:
Array ( [name] => bkjia.jpg [type] => image/pjpeg [tmp_name] => /tmp/phprY0loE [error] => 0 [size] => 71189 )
The Mimetype of images in jpg format is image/pjpeg. Since Chrome or Firefox is used during development, image/pjpeg is not added during judgment, so images in jpg format cannot be recognized by IE-based browsers.
The following is a comparison of the formats of images in different browsers:
firefox image/jpeg image/bmp image/gif image/png ie 6 image/pjpeg image/bmp image/gif image/x-png ie 7 image/pjpeg image/bmp image/gif image/x-png ie 8 image/pjpeg image/bmp image/gif image/x-png
When uploading pictures, IE will translate jpg and jpeg into image/pjpeg, and png into image/x-png. Firefox is very standard: jpg and jpeg are translated into image/jpeg, and png is translated into image/png.
It will be OK if the program is changed to this.
switch($type) { case "image/jpeg": $resultImage = imagecreatefromjpeg($original); imagejpeg($resultImage, $target, $quality); break; case "image/pjpeg": $resultImage = imagecreatefromjpeg($original); imagejpeg($resultImage, $target, $quality); break; case "image/png": $resultImage = imagecreatefrompng($original); imagepng($resultImage, $target, $quality_png); break; case "image/gif": $resultImage = imagecreatefromgif($original); imagegif($resultImage, $target, $quality); break; default : die("不支持此文件类型"); exit; }