Handle error when getimagesize can't find a file

前端 未结 4 461
挽巷
挽巷 2021-02-05 06:53

when I\'m trying to getimagesize($img) and the image doesn\'t exist, I get an error. I don\'t want to first check whether the file exists, just handle the error.

4条回答
  •  广开言路
    2021-02-05 07:07

    This solution has worked for me.

    try {
        if (url_exists ($photoUrl) && is_array (getimagesize ($photoUrl)))
        {
            return $photoUrl;
        }
    } catch (\Exception $e) { return ''; }
    

提交回复
热议问题