Uploading JPG images in IE problem _php tutorial

Source: Internet
Author: User
Tags bmp image imagejpeg
Some time ago did a picture upload small program, today some people say JPG images can not upload. I was in the local chrome, Firefox test, found no problem, upload normal. I asked him what browser he used to be the window of the world and 360 ... I'm embarrassed. I think, is not the problem of IE? So I was in IE under the test, sure enough. 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 ;d efault:d IE ("This file type is not supported");        Exit;}

Google later, found that the JPG format of the picture under IE does have some differences.

Upload a JPG image under IE, and then print the information for the uploaded file as follows:

Array ([name] = Bkjia.jpg[type] [image/pjpeg[tmp_name] =/tmp/phpry0loe[error] = 0[size] + 71189)

JPG format of the picture MimeType for Image/pjpeg. Since the development of Chrome or Firefox development, in the judgment is not added image/pjpeg, so that the JPG format of the image in the IE kernel browser can not be recognized.

The following is the format of each format picture in different browsers in comparison:

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 you pass a picture, IE will translate JPG and JPEG into image/pjpeg,png and translate it into image/x-png. And Firefox is very standard: JPG, jpeg translation into Image/jpeg,png translated into image/png.

It's OK to change the program 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 ;d efault:d IE ("This file type is not supported");        Exit;}

http://www.bkjia.com/PHPjc/752535.html www.bkjia.com true http://www.bkjia.com/PHPjc/752535.html techarticle some time ago did a picture upload small program, today some people say JPG images can not upload. I was in the local chrome, Firefox test, found no problem, upload 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.