Php determines whether the image format is JPG-PHP source code

Source: Internet
Author: User
Ec (2); in fact, many methods are also very simple, for example, $ _ FILES [userfile] [type] is to judge before the file is uploaded. there is also a getimagesize -- get the image size while getimagesize returns and parameters are as follows. returns an array with four units. Index 0 contains the pixel value of the image width, and index 1 contains the pixel value of the Image Height. Index 2 is the mark of the image type: 1GIF, 2JPG, 3PNG script ec (2); script

In fact, there are many simple methods, such

$ _ FILES ['userfile'] ['type'] is to judge before the file is uploaded.

There is also a getimagesize -- get the image size while getimagesize returns and parameters are as follows.

Returns an array with four units. Index 0 contains the pixel value of the image width, and index 1 contains the pixel value of the Image Height. Index 2 is the mark of the image type: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF (intel byte order), 8 = TIFF (motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM. These tags correspond to the newly added IMAGETYPE constant in PHP 4.3.0. Index 3 is a text string with the content "height =" yyy "width =" xxx "and can be directly used for IMG marking.

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.