Question about uploading jpg images in IE _ PHP Tutorial

Source: Internet
Author: User
Tags bmp image imagejpeg
Question about uploading jpg images in IE. 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 time he used a small program to upload images. today someone said 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 ;}

Bytes. I tested it in Chrome and Firefox locally and found that the upload was normal. I asked him what he used...

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.