tags:

views:

50

answers:

3

Is there a good method for making sure that an uploaded file is an image in PHP?

+2  A: 

Use the Fileinfo functions.

Ignacio Vazquez-Abrams
How would I do that?
Brian
Use this -> http://www.php.net/manual/en/function.finfo-file.php
AntonioCS
A: 

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.

Devin Ceartas
A: 

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.

djn