您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP实现远程下载文件到本地_PHP教程

2025/10/30 10:03:28发布8次查看
php实现远程下载文件到本地 经常写采集器发布接口需要使用到远程附件的功能,所以自己写了一个php远程下载文件到本地的函数,一般情况下已经够用了,如果服务器支持curl函数,程序则会优先选择curl,有需要的小伙伴可以参考下。
代码很简单就不多废话了,直接奉上:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
array(
method=>get,
header=>,
timeout=>$timeout)
);
$context = stream_context_create($opts);
if(@copy($url, $file, $context)) {
//$http_response_header
return $file;
} else {
return false;
}
}
}
?>
再来个远程下载文件到服务器
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// maximum execution time in seconds
set_time_limit (24 * 60 * 60);
if (!isset($_post['submit'])) die();
// folder to save downloaded files to. must end with slash
$destination_folder = 'temp/';
$url = $_post['url'];
$newfname = $destination_folder . basename($url);
$file = fopen ($url, rb);
if ($file) {
$newf = fopen ($newfname, wb);
if ($newf)
while(!feof($file)) {
fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
}
}
if ($file) {
fclose($file);
}
if ($newf) {
fclose($newf);
}
?>
以上所述就是本文的全部内容了,希望大家能够喜欢。
http://www.bkjia.com/phpjc/1000064.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1000064.htmltecharticlephp实现远程下载文件到本地 经常写采集器发布接口需要使用到远程附件的功能,所以自己写了一个php远程下载文件到本地的函数,一般情况...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product