What is the best and fastest way to check if the image is valid in PHP?

前端 未结 6 1337
别那么骄傲
别那么骄傲 2021-01-01 11:07

What is the best and fastest way to check if the image is valid in PHP ? I need it to be able to check GIF, JPG as well as PNG images.

6条回答
  •  甜味超标
    2021-01-01 11:58

    I use this:

    function is_image($path)
    {
        $a = getimagesize($path);
        $image_type = $a[2];
    
        if(in_array($image_type , array(IMAGETYPE_GIF , IMAGETYPE_JPEG ,IMAGETYPE_PNG , IMAGETYPE_BMP)))
        {
            return true;
        }
        return false;
    }
    

提交回复
热议问题