What is the best way to determine whether or not a file is an image in PHP?

前端 未结 12 638
有刺的猬
有刺的猬 2021-01-22 07:25

I have a sever which people can upload files to. The problem is that some of the filenames are mangled (dont have any extension) and so I cannot immediately determine file type.

12条回答
  •  半阙折子戏
    2021-01-22 07:57

    If you have the GD2 extension enabled, you could just use that to load the file as an image, then if it returns invalid you can catch the error and return FALSE, otherwise return TRUE.

提交回复
热议问题