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

前端 未结 12 606
有刺的猬
有刺的猬 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:47

    Look at image magic identify. http://www.imagemagick.org/script/identify.php

    The php wrapper is here: http://www.php.net/manual/en/function.imagick-identifyimage.php

    Or if you just want to validate that it's an image (and don't care about the meta data): http://www.php.net/manual/en/function.imagick-valid.php

提交回复
热议问题