开发者

ensure that uploaded file is image in PHP

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜