网站地图    收藏   

主页 > php专栏 > php函数大全 >

php判断远程图片是否存在 - php函数

来源:自学PHP网    时间:2014-11-25 00:26 作者: 阅读:次

[导读] functionimg_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_retu......

php判断远程图片是否存在

  1. function img_exits($url) 
  2. { 
  3.     $ch = curl_init(); 
  4.     curl_setopt($ch, curlopt_url,$url); 
  5.     curl_setopt($ch, curlopt_nobody, 1); // 不下载 
  6.     curl_setopt($ch, curlopt_failonerror, 1); 
  7.     curl_setopt($ch, curlopt_returntransfer, 1); 
  8.  
  9.     if(curl_exec($ch)!==false) 
  10.         return true; 
  11.     else 
  12.         return false; 
  13. } 
  14.   
  15.  
  16. //方法二,代码如下: 
  17.  
  18. function img_exists($url)  
  19. { 
  20.     if(file_get_contents($url,0,null,0,1)) 
  21.         return 1; 
  22. else 
  23.         return 0; 
  24. } 
  25.  
  26. // 
  27.  
  28. /** 
  29. @title:如何检查某个远程文件是否存在(php5) 
  30. @author:axgle 
  31. @version:1.0 
  32. *//开源代码phpfensi.com 
  33. $url='http://www.phpfensi.com/'; 
  34. echo url_exists($url); 
  35.   
  36. function url_exists($url) { 
  37.   
  38.         $head=@get_headers($url); 
  39.         if(is_array($head)) { 
  40.                 return true; 
  41.         } 
  42.         return false; 
  43.   
  44. } 
  45.  
  46. ?> 
  47.   
  48. 网页方法,代码如下: 
  49. <script   language= "javascript">  
  50. function   geturl(url)  
  51. {  
  52.         var   xmlhttp   =   new   activexobject( "microsoft.xmlhttp ");  
  53.         xmlhttp.open( "get ",url,false);  
  54.         xmlhttp.send();  
  55.         if   (xmlhttp.readystate==4)  
  56.             alert((xmlhttp.status==200)? "文件存在 ": "文件不存在 ");  
  57. }  
  58. </script>  
  59. 请输入文件地址: <input   name= "file "   id= "file "   value= "http://www.phpfensi.com ">  
  60. <button   onclick= "geturl(file.value) "> 检测地址 </button> 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论