开发者

ensure that uploaded file is image in PHP

开发者 https://www.devze.com 2022-12-19 17:04 出处:网络
Is there a good method for making sure that an uploaded fil开发者_C百科e is an image in PHP?Use the Fileinfo functions.Pass the received file to the getimagesize() function. If the file is an image (o

Is there a good method for making sure that an uploaded fil开发者_C百科e is an image in PHP?


Use the Fileinfo functions.


Pass the received file to the getimagesize() function. If the file is an image (of supported type) you'll get back an array, with the image type stored as third member of the array. If the file is not an image result will be false.


One method that goes beyond asking it if it an image using MIME, FileInfo, etc. is to try and do something with it as an image -- load up with GD or ImageMagik and use that to write a new copy to the desired location.


Here:

if(strpos($_FILES["fieldname"]["type"], "image") !== FALSE) {
    // is an image
} else {
    // is no image
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号