不下载图片,只判断是否存在
我是这样用的
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
$result = curl_exec($curl);
$found = false;
if($result !== false) {
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($statusCode == 200) {
$found = true;
}
}
curl_close($curl);
可是对https的图片链接$statusCode一直是404
怪我咯2017-04-11 08:59:35
试试
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false)
判断下返回的东西是否404
$contents = curl_exec($ch);
if(preg_match("/404/", $contents)){
return false;
}else{
return true;
}
怪我咯2017-04-11 08:59:35
可以用get_headers
啊
<?php
$url='https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png';
print_r(get_headers($url));