I have been researching this topic for the last couple weeks now and it's really beginning to bug me that I can't find a definitive answer for it.
I have a website where users are able to upload their own profile picture. I want to ensure the only files that are allowed to be uploaded are JPEGs, GIFs and PNGs
Obviously using the mime type sent by the browser to validate is a big no no as it can easily be spoofed so that rules that out, and it goes without saying never to validate on the file extension.
Next there is the new(ish) finfo functions PHP provides. I have been using this for the time being as it seemed to be the best available method but reading the comments at http://www.php.net/manual/en/ref.fileinfo.php it seems that can be tricked too. Also I'm not sure if just checking if the returned MIME type is image/jpeg, image/gif, or image/png is too restrictive?
Then there is the getimagesize() function which I read returns false for anything not an image which seems perfect, but if that is the case why are there so many accepted answers on here saying use finfo?
Lastly there is the system() or exec() call, which seems a bit dangerous allowing the user to specify part of a system call!
So my question is, what method should I use? I want to make my script as secure as possible but also open enough so regular users don't get punished in their valid images being rejected by the script