We used php curl related functions to access remote files, and then judged whether the file can be used normally based on the return status. Friends in need can refer to
The code is as follows 代码如下 | 复制代码 |
//判断远程文件 function check_remote_file_exists($url) { $curl = curl_init($url); // 不取回数据 curl_setopt($curl, CURLOPT_NOBODY, true); // 发送请求 $result = curl_exec($curl); $found = false; // 如果请求没有发送失败 if ($result !== false) { // 再检查http响应码是否为200 $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ($statusCode == 200) { $found = true; } } curl_close($curl);
return $found; }
| |
Copy code |
//Judge remote files function check_remote_file_exists($url) { $curl = curl_init($url); //Do not retrieve data curl_setopt($curl, CURLOPT_NOBODY, true); //Send request $result = curl_exec($curl); $found = false; //Failed if the request was not sent if ($result !== false) { // Check again whether the http response code is 200 $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ($statusCode == 200) { $found = true; } } curl_close($curl);
代码如下 | 复制代码 | $url = "/upload/201110/20111008192257383.gif"; $array = get_headers($url,1); if(preg_match('/200/',$array[0])){ echo ""; print_r($array); }else{ echo "无效url资源!"; } | return $found; } |
Method 2
http://www.bkjia.com/PHPjc/444739.htmlwww.bkjia.com
trueTechArticleWe use php curl related functions to access remote files, and then judge whether the file can be used normally based on the return status. Friends in need can refer to the code and copy it as follows...