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

  哈尔滨品用软件有限公司致力于为哈尔滨的中小企业制作大气、美观的优秀网站,并且能够搭建符合百度排名规范的网站基底,使您的网站无需额外费用,即可稳步提升排名至首页。欢迎体验最佳的哈尔滨网站建设