php如何判断一个远程文件是否存在呢?下面是作者在网上找到的方法,在这里和大家分享一下。
更准确的判断方法请参考:
使用 php 检查一个通过 http 协议访问的网络文件是否存在
//php判断远程文件是否存在
function url_exists($url){
$handle=curl_init($url);
if(false===$handle){
return false;
}
curl_setopt($handle,CURLOPT_HEADER,false);
curl_setopt($handle,CURLOPT_FAILONERROR,true);
curl_setopt($handle,CURLOPT_NOBODY,true);
curl_setopt($handle,CURLOPT_RETURNTRANSFER,false);
$connectable=curl_exec($handle);
//http://www.phpernote.com/php-function/744.html
curl_close($handle);
return $connectable;
}