在PHP中验证图像

I'm using GD to create jpegs from files that a user uploads.

What is the best way to validate that the image the user has uploaded is valid?

By valid I mean that the file is not a corrupt image that GD won't like, I do extension testing client side so they can only upload jpegs/gifs/pngs.

Thanks

You could use getimagesize. It will return FALSE if the image could not be loaded. It has support for most image types.

getImageSize would be your best choice but, be careful, if the file results are not valid you will get a warning. Using @ before built in imagesize function will be ideal.