PHP to determine whether the picture is a standard picture (to prevent tampering with the picture below)

Source: Internet
Author: User
PHP to determine whether a picture is a standard picture (prevent tampering with the image upload)

In the project security, found that a department of the project image upload only the suffix is checked, resulting in some code of the ' picture ' can also be uploaded to the server, there is a major hidden danger. Wrote a method to verify the correctness of the picture. (This method can not be fully verified, the image source code is not able to judge, but the image processing such as watermark, the image containing the code will be invalid as PHP execution)

?

/* * To determine if the uploaded image is a standard image * $file $FILES ['] get the value *return normal picture true;  Abnormal picture false; */function Isimage ($file) {if ($file ["type"] = = "Image/gif") {@ $im = imagecreatefromgif ($file [' tmp_name ']);} elseif ($ file["type"] = = "Image/png" | | $file ["type"] = = "Image/x-png") {@ $im = imagecreatefrompng ($file [' tmp_name ']);} else {@ $im = Imagecreatefromjpeg ($file [ ' Tmp_name ');} if ($im ==false) {return false;} Else{return true;}}
  • Related Article

    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.