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;}}