用于上传图像的图像格式测试?

With PHP, how can I test that an uploaded file is a valid gif, jpg, or png image?

You can also use exif_imagetype

Take a look at mime_content_type

Edit

Never mind, that function has been depreciated. Use finfo_open

$finfo = new finfo(FILEINFO_MIME_TYPE);

echo $finfo->file('images/file.png'); // image/png

getimagesize() will parse the file header for "magic bytes" identifying the format. Apart from loading the file into GD and re-saving it, this is the most reliable way of making sure a file is an image.

A number of formats is supported, including BMP, TIFF and PSD.

If you have GD correctly set up, supporting the right formats, this should do it.

$info = getimagesize("file");
echo $info["mime"];