轉(zhuǎn)載請注明來源:php判斷遠(yuǎn)程圖片是否存在
- 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:如何檢查某個遠(yuǎn)程文件是否存在(php5)
- @author:axgle
- @version:1.0
- *//開源代碼phpfensi.com
- $url='http://www.phpfensi.com/';
- echo url_exists($url);
- function url_exists($url) {
- $head=@get_headers($url);
- if(is_array($head)) {
- return true;
- }
- return false;
- }
- ?>
- 網(wǎng)頁方法,代碼如下:
- <script language= "javascript">
- 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.phpfensi.com ">
- <button onclick= "geturl(file.value) "> 檢測地址 </button>
哈爾濱品用軟件有限公司致力于為哈爾濱的中小企業(yè)制作大氣、美觀的優(yōu)秀網(wǎng)站,并且能夠搭建符合百度排名規(guī)范的網(wǎng)站基底,使您的網(wǎng)站無需額外費(fèi)用,即可穩(wěn)步提升排名至首頁。歡迎體驗(yàn)最佳的哈爾濱網(wǎng)站建設(shè)。
