PHP如何下载远程文件到指定目录
PHP用curl可以轻松实现下载远程文件到指定目录:
<?php class Download { public static function get($url, $file) { return file_put_contents($file, file_get_contents($url)); } public static function curlGet($url, $file) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 0); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $file_content = curl_exec($ch); curl_close($ch); $downloaded_file = fopen($file, 'w'); fwrite($downloaded_file, $file_content); fclose($downloaded_file); } public static function openGet($url, $file) { $in = fopen($url, "rb"); $out = fopen($file, "wb"); while ($chunk = fread($in,8192)) { fwrite($out, $chunk, 8192); } fclose($in); fclose($out); } /** * * 创建目录,支持递归创建目录 * @param String $dirName 要创建的目录 * @param int $mode 目录权限 */ public static function smkdir($dirName , $mode = 0777) { $dirs = explode('/' , str_replace('\\' , '/' , $dirName)); $dir = ''; foreach ($dirs as $part) { $dir.=$part . '/'; if ( ! is_dir($dir) && strlen($dir) > 0) { if ( ! mkdir($dir , $mode)) { return false; } if ( ! chmod($dir , $mode)) { return false; } } } return true; } }更多PHP相关知识,请访问PHP教程!
以上就是PHP如何下载远程文件到指定目录的详细内容,更多请关注jquery中文网其它相关文章!
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://www.juheyunku.com/jiaob/shell/10449.shtml
相关文章
热门TAG
命令 权重 外链 企业网站 白帽 php 织梦教程 dedecms修改内容 javascript 织梦 功能 标签 调用 详解 服务器 网站流量 实例解析 Dedecms 织梦cms HTML tags标签 python jquery教程 jquery windows SEO优化 蜘蛛 搜索引擎 网站收录 JSP最新文章
-
Centos下PHP5升级为PHP7的方法
时间:2021-01-03
-
在php当中常量和变量的区
时间:2020-12-29
-
PHP中经典的四大排序算法
时间:2020-12-29
-
dw怎么运行php文件?
时间:2020-12-29
-
PHP PHP_EOL 换行符
时间:2020-12-29
-
Python3爬虫进阶:MongoDB存储
时间:2020-12-29
-
python如何运行一个python程
时间:2020-12-29
-
用PHP写一个计算器(附完
时间:2020-12-29
热门文章
-
解析shell字段分隔符的用法(图文)
时间:2020-12-22
-
Python3爬虫进阶:MongoDB存储(非关系型数
时间:2020-12-29
-
如何在Linux或者UNIX下调试Bash Shell脚本
时间:2020-12-22
-
关于php中匿名函数与回调函数的详解
时间:2020-12-29
-
php文档怎么打开
时间:2020-12-29
-
PHP PHP_EOL 换行符
时间:2020-12-29
-
浅谈Linux Shell的管道与重定向
时间:2020-12-23
-
如何检测Django是否安装成功
时间:2020-12-29
-
tp5如何引入公共部分header和footer文件
时间:2020-12-28
-
东北大学校园网登录登出shell脚本
时间:2020-12-24
