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;
}
}
转自:https://www.awaimai.com/2105.html
关注微信公众号:lovephp
PHP下载远程文件到指定目录的更多相关文章
- 不借助autolt实现下载文件到指定目录
今天尝试了下不用借助autolt完成下载文件到指定目录, 好处:在于集成回归,远程机可以绕过执行autolt程序权限问题,导致autolt程序无法调用,不能完成脚本的回归 Firefox浏览器已经成功 ...
- Jenkins拉取Git远程仓库中指定目录至本地指定目录
Jenkins拉取源码是非常实用的操作,比如每天在跑自动化测试前,拉取Git远程仓库中最新的脚本至本地.那么,Jenkins如何拉取Git远程仓库中指定目录至本地指定目录呢?下面来看看具体的设置方法. ...
- WPF下载远程文件,并显示进度条和百分比
WPF下载远程文件,并显示进度条和百分比 1.xaml <ProgressBar HorizontalAlignment="Left" Height="10&quo ...
- java下载远程文件到本地
java下载远程文件到本地(转载:http://www.cnblogs.com/qqzy168/archive/2013/02/28/2936698.html) /** * 下载远程文 ...
- winform复制文件到指定目录
执行步骤 弹出选择对话框:var openFileDialog = new OpenFileDialog(); 设置选择内容,如所有图片:openFileDialog.Filter="图像文 ...
- Linux解压文件到指定目录
Linux解压文件到指定目录 tar在Linux上是常用的打包.压缩.加压缩工具,他的参数很多,折里仅仅列举常用的压缩与解压缩参数 参数:-c :create 建立压缩档案的参数:-x : 解压缩压缩 ...
- Git .gitignore使用 -- 过滤class文件或指定目录
1. 进入当前的项目根目录 执行 git init touch .gitignore 2. 过滤class文件或指定目录 *.class /target/ 3. 提交 git add . 将所有文件提 ...
- 解压.zip,.tar.gz文件到指定目录,重命名文件
1.解压文件到指定目录 /** * 解压文件到指定目录 * zipFile:要解压的文件 * descDir:解压到哪个文件 * */ @SuppressWarnings("rawtypes ...
- 使用CertUtil.exe下载远程文件
使用CertUtil.exe下载远程文件 证书 https://www.cnblogs.com/17bdw/p/8728656.html 1.前言 经过国外文章信息,CertUtil.exe下载恶意软 ...
随机推荐
- Devexpress Xtrareport 打印报表
需要引用 Using Devexpress.Xtrareport.UI: Using Devexpress.XtraPrinting.Localiztion 实例化报表,xtrareport my=n ...
- Flex Validator的小BUG
Flex中对同一控件如TextInput进行多种格式校验的情况下,如不注意,可能导致错误信息不显示的BUG,比如 <fx:Array id="validators"> ...
- image压缩
public byte[] compressPic(byte[] data) { if(data.length == 0){ return new byte[0]; } Image img = nul ...
- Python数据报协议以及sockersever模块的使用
一.基于UDP协议的套接字 UDP协议 UDP 是User Datagram Protocol的简称, 中文名是用户数据报协议,是OSI(Open System Interconnection,开放式 ...
- 零基础逆向工程36_Win32_10_互斥体_互斥体与临界区的区别
1 引言 讲了第二个内核对象,互斥体.前面已经学过一个内核对象,线程.这节讲两个函数,WaitForSingleObject()和WaitForMultipleObjects().因此这两个函数是根据 ...
- python3绘图示例4(基于matplotlib:箱线图、散点图等)
#!/usr/bin/env python# -*- coding:utf-8 -*- from matplotlib.pyplot import * x=[1,2,3,4]y=[5,4,3,2] # ...
- So you want to write a desktop app in Python
So you want to write a desktop app in Python Thomas Kluyver 2014-06-16 23:55 51 Comments Source This ...
- ModuleNotFoundError: No module named 'yaml'
ModuleNotFoundError: No module named 'yaml' 需要安装 pyyaml 包
- C4C销售订单中业务伙伴的自动决定功能Partner determination procedure
例子:我新建一个Sales Order,account 字段选择ID为1001的Account:Porter LLC 创建成功后,观察这个Sales Order的Involved Party里,Bil ...
- spring使用bean
ApplicationContext 应用上下文,加载Spring 框架配置文件 加载classpath: new ClassPathXmlApplicationContext(“applicatio ...