我们利用了php curl相关函数来访问远程文件,然后根据返回状态来判断文件是否可以正常使用,有需要的朋友可以参考一下,代码如下:
-
- 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) {
-
- $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
- if ($statusCode == 200) {
- $found = true;
- }
- }
- curl_close($curl);
-
- return $found;
- }
方法二,代码如下:
- $url = "/upload/201110/20111008192257383.gif";
- $array = get_headers($url,1);
- if(preg_match('/200/',$array[0])){
- echo "<pre/>";
- print_r($array);
- }else{
- echo "无效url资源!";
- }
|