时间:2021-07-01 10:21:17 帮助过:2人阅读
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; }
后来google了下,发现关于jpg格式的图片在IE下确实有些差异。
在IE下上传一副jpg图片,然后打印该上传文件的信息如下:
Array ( [name] => bkjia.jpg [type] => image/pjpeg [tmp_name] => /tmp/phprY0loE [error] => 0 [size] => 71189 )
jpg格式的图片的Mimetype为image/pjpeg。由于开发中都用Chrome或者Firefox开发,在判断时并没有加image/pjpeg,所以导致jpg格式的图片在IE内核的浏览器无法被识别。
下面是各格式图片在不同浏览器中的格式对照:
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
传图片时,ie会把 jpg、jpeg翻译成image/pjpeg,png翻译成image/x-png 。而火狐则很标准:jpg、jpeg翻译成image/jpeg,png翻译成image/png。
程序改成这样就OK了。
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; }
http://www.bkjia.com/PHPjc/752535.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/752535.htmlTechArticle前一段时间做了一个图片上传的小程序,今天有人说jpg图片上传不了。我在本地Chrome、Firefox测了下,发现没有问题,上传正常。我问他用什...