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

前端 未结 12 599
有刺的猬
有刺的猬 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 08:06

    If you need a fast solution, use imagesx() and imagesy(). There is also a fast way to check large image file dimensions, by reading just a small amount of data from the file header. Explained in more detail in the following url:

    http://hungred.com/useful-information/php-fastest-image-width-height/

提交回复
热议问题