Problem uploading JPG images in IE_PHP tutorial

WBOY
Release: 2016-07-13 10:33:12
Original
783 people have browsed it

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;
	}
Copy after login

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
)
Copy after login

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
Copy after login

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;
	}
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/752535.htmlTechArticleI made a small program for image uploading some time ago, but today someone said that jpg images 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...
Related labels:
ie
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template