当前位置:首页 > PHP教程 > php函数 > 列表

php判断远程图片是否存在

发布:smiling 来源: PHP粉丝网  添加日期:2014-08-16 10:36:09 浏览: 评论:0 
  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> 

Tags: php判断远程 图片是否存在

分享到: