PHP判断远程文件是否存在
2016-07-20 10:38
615 查看
函数描述及例子 <? //测试代码 $str_url = 'http://127.0.0.2/viewarticle.php?id=119617'; $exits = remote_file_exists($str_url); echo $exists ? "Exists" : "Not exists"; ?>
方法一(需要开启allow_url_fopen):
方法二(需要服务器支持Curl组件): <?php function check_remote_file_exists($url) { $curl = curl_init($url); // 不取回数据 curl_setopt($curl, CURLOPT_NOBODY, true); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET'); // 发送请求 $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; } $url = "http://cn.wordpress.org/wordpress-3.3.1-zh_CN.zip"; echo check_remote_file_exists($url); // 返回1,说明存在。 ?>
相关文章推荐
- Thinkphp htmllist 标签的使用
- ThinkPHP的模版中调用session数据的方法
- thinkphp默认的URL如何访问
- PHP写文件函数
- thinkphp实现文件下载函数
- ThinkPHP使用详解
- thinkphp引入第三方类库
- php 上传大文件主要涉及配置upload_max_filesize和post_max_size两个选项
- thinkphp中find()和select的区别
- ThinkPHP中initialize和construct的不同
- thinkphp中联表查询(多表)
- thinkphp自带的调试方法
- thinkphp框架命名规范
- 【转】关于PHP的header("P3P: CP=CURa……")
- php实现登录tplink WR882N获取IP和重启的方法
- Laravel在model类里关闭timestamps
- php提交表单不刷新页面
- PHP编译安装时常见错误解决办法
- PHP采集curl应用的一点小疑惑
- Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境搭建教程