PHP判断远程链接URL是否存在
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);
if(curl_exec($ch)!==false)
return true;
else
return false;
}
方法二:
function img_exists($url)
{
if(file_get_contents($url,0,null,0,1))
return 1;
else
return 0;
}
方法三:
/**
@title:如何检查某个远程文件是否存在(php5)
@author:axgle
@version:1.0
*/
$url='http://www.hilo8.com/';
echo url_exists($url);
function url_exists($url) {
$head=@get_headers($url);
if(is_array($head)) {
return true;
}
return false;
}
?>
方法四:
$url='http://www.hilo8.com/404.htm'
if(!$fp=@fopen($url,"r")){
echo "远程文件不存在!";
}
else{
echo "远程文件存在!";
}
方法五:网页特效方法
<script language= "网页特效 ">
function geturl(url)
{
var xmlhttp = new activexobject( "microsoft.xmlhttp ");
xmlhttp.open( "get ",url,false);
xmlhttp.send();
if (xmlhttp.readystate==4)
alert((xmlhttp.status==200)? "文件存在 ": "文件不存在 ");
}
</script>
请输入文件地址: <input name= "file " id= "file " value= "http://www.hilo8.com">
<button onclick= "geturl(file.value) "> 检测地址 </button>
上一篇:PHP get_headers()函数详解
下一篇:php下载文件的函数
讨论数量:1
天涯网魂 3 杠 5 星2012-08-27 12:29:24
function url_exists($url){
$head=@get_headers($url);
if(is_array($head)) {
if(preg_match('/200/',$head[0])){ //判断是否返回页面成功
return true;
}else{
return false;
}
}
return false;
}