PHP快速判断远程图片是否存在函数(不下载图片)

Share on:

网上找了一些PHP判断远程图片是否存在方法,有的不能用,有的加载了全部图片,导致响应很慢

下面方法亲测可用,赞哦~~

function img_exits($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_NOBODY, 1);
    curl_setopt($ch, CURLOPT_FAILONERROR, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $contents =  curl_exec($ch);
    if($contents!==false)
        return true;
    else
        return false;
}
闽ICP备12003472号-7