check if image exists php

前端 未结 3 1334
清酒与你
清酒与你 2021-01-11 12:24

I am in the middle of coding up a property portal. I am stuck on checking images. I know how to check if an image url is set. But the problem is detecting if there is actual

3条回答
  •  抹茶落季
    2021-01-11 13:07

    function exists($uri)
    {
        $ch = curl_init($uri);
        curl_setopt($ch, CURLOPT_NOBODY, true);
        curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
    
        return $code == 200;
    }
    

提交回复
热议问题