方法一: 使用curl
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);
if(curl_exec($ch)!==false)
return true;
else
return false;
}
方法二: 使用file_get_contents
function img_exists($url)
{
if(file_get_contents($url,0,null,0,1))
return 1;
else
return 0;
}
判断某个文件是否存在
$url=’http://www.111cn.net/’;
echo url_exists($url);
function url_exists($url) {
$head=@get_headers($url);
if(is_array($head)) {
return true;
}
return false;
}