当前位置:网站首页>[yellow code] PHP saves remote resources locally
[yellow code] PHP saves remote resources locally
2022-07-16 05:30:00 【Yellow Size】
Ah yard generally has less nonsense , Just dump the code , Don't know how to buckle me , If you don't understand it, you can only buckle your feet ,OK?
/**
* Save remote resources locally
* @param string $source Resources to address
* @param string $local Local address
* @return array
*/
private function execDown($source,$local)
{
if (!is_dir(dirname($local))) {
mkdir(dirname($local),0755,true);
}
$localFile = fopen($local, 'w');
$ch = curl_init(); // initialization cURL conversation
curl_setopt($ch,CURLOPT_URL,$source); // Remote address
curl_setopt($ch, CURLOPT_POST, 0); // Not POST request
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3000); // Maximum waiting time for successful connection
curl_setopt($ch, CURLOPT_FILE, $localFile); // The local path
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // https request Do not verify certificate
curl_exec($ch);
if (curl_error($ch)) {
$res = [
'status' => 0,
'message' => curl_error($ch),
'time' => 0,
'fileinfo' => []
];
fclose($localFile);
curl_close($ch);
return $res;
} else {
$info = curl_getinfo($ch);
curl_close($ch);
fclose($localFile);
if (filesize($local) != $info['size_download']) {
$res = [
'status' => 0,
'message' => ' Incomplete download data , Please download again ',
'time' => $info['total_time'],
'fileinfo' => []
];
return $res;
}
$res = [
'status' => 1,
'message' => ' Download complete ',
'time' => $info['total_time'],
'fileinfo' => [
'file_type' => $info['content_type'],
'file_size' => $info['size_download'],
'remote_path' => $source,
'local_path' => $local,
]
];
return $res;
}
}边栏推荐
猜你喜欢

Idea automatically generates entity classes of corresponding tables in the database

36.js--原型链2--(笔试题为主)

Flask 开发 & Get/Post 请求

Blue Bridge Cup: the second game of the 13th provincial competition of single chip microcomputer group

38.js--原型练习案例(校招面试题)

完整在pycharm上通过torch调用GPU(最细节)
![Random signal analysis, 2nd Edition [edited by Zhao Shuqing and Zheng Wei] (part) answer to homework after class (written by myself)](/img/13/edd5af20fb9a9514339d8ae21eed71.jpg)
Random signal analysis, 2nd Edition [edited by Zhao Shuqing and Zheng Wei] (part) answer to homework after class (written by myself)

Understanding service governance in distributed development

el-button 显示与禁用

vue+axios+mysql实现分页查询,条件查询以及批量删除
随机推荐
将列表数据转换为树形数据
Idea自动导出数据库中表的sql语句
ES6--箭头函数
【prettier】通过prettier自动格式化代码不生效
Jmeter相关知识整理
遍历器总结
Svelte 官方入门教程(4)—— 模板逻辑
39.js--作用域
【黄啊码】MySQL的这些小知识点,初入门的你必须得学会
蓝桥杯单片机第13届省赛题
window系统盘瘦身(开发)
Understanding service governance in distributed development
ES6新增的class类
oracle 学习
Why blog?
[Tensorflow2] 梯度反转层(GRL)与域对抗训练神经网络(DANN)的实现
ES6内置对象的新方法新特性
【黄啊码】MySQL入门—1、SQL 的执行流程
2022暑期实践(PowerDesigner教程学习记录)(第一周)
FTP 上传文件脚本说明