Reputation: 27392
Is there a good method for making sure that an uploaded file is an image in PHP?
Upvotes: 3
Views: 1699
Reputation: 2068
Here:
if(strpos($_FILES["fieldname"]["type"], "image") !== FALSE) {
// is an image
} else {
// is no image
}
Upvotes: -2
Reputation: 3948
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
.
Upvotes: 1
Reputation: 4829
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.
Upvotes: 0