$baidu_logo = "http://pr.bdimg.com/static/princess/img/misc/baidu_logo.gif";
$logo = "http://pr.bdimg.com/static/princess/img/misc/logo.gif";
var_dump(my_file_exists($logo));
echo "\n";
var_dump(my_file_exists($baidu_logo));
function my_file_exists($file, $basePath=''){
if(preg_match('|^http://|',$file)){//如果是远程文件
$ch = curl_init($file);
curl_setopt($ch, CURLOPT_HEADER, 1); //输出文件头信息
curl_setopt($ch, CURLOPT_NOBODY, 1); //不输出文件主体
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //将curl_exec()返回到变量
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); //设置超时
$contents = curl_exec($ch); //获取远程文件信息
return preg_match('|HTTP/1.1 200|', $contents)?true:false; //如果状态不是200,就表示获取失败。
}
return file_exists($basePath.$file);
}