Question about uploading JPG images in IE

Source: Internet
Author: User
Tags bmp image imagejpeg

Some time ago I made a small program for uploading images. Today, some people say that JPG images cannot be uploaded. I tested it in Chrome and Firefox locally and found that the upload was normal. I asked him what browser he used. It turned out to be the window of the world, and there was 360 ...... I was sorry. I think, is it a problem with IE? So I tested it in IE. The original program 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 ("this file type is not supported"); exit ;}

Later, google found that jpg images are indeed different from IE images.

Upload a jpg image under IE and print the following information:

Array([name] => bkjia.jpg[type] => image/pjpeg[tmp_name] => /tmp/phprY0loE[error] => 0[size] => 71189)

The Mimetype of a jpg image is image/pjpeg. Because Chrome or Firefox is used in development, image/pjpeg is not added during the judgment, so jpg images cannot be recognized in IE kernel browsers.

The following is a comparison of the formats of images in different browsers:

firefox image/jpeg image/bmp image/gif image/pngie 6 image/pjpeg image/bmp image/gif image/x-pngie 7 image/pjpeg image/bmp image/gif image/x-pngie 8 image/pjpeg image/bmp image/gif image/x-png

When uploading images, ie translates jpg and jpeg files into image/pjpeg files and png files into image/x-png files. Firefox is very standard: jpg and jpeg are translated into image/jpeg, and png is translated into image/png.

The program is changed to 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 = hour ($ original); imagepng ($ resultImage, $ target, $ quality_png); break; case "image/gif": $ resultImage = imagecreatefromgif ($ original ); imagegif ($ resultImage, $ target, $ quality); break; default: die ("this file type is not supported"); exit ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.