当前位置:首页 > PHP > 正文内容

php代理下载,php代下载文件,php下载远程文件,php远程文件下载

高老师7年前 (2019-09-28)PHP1632

经常我们下载国外资源容易被墙,可以通过php脚本获取远程文件流然后输出给我们的浏览器来下载。

<?php

//设置下载文件的url
$url = 'https://mirrors.huaweicloud.com/ubuntukylin/ubuntukylin-19.04-enhanced-amd64.iso';

//设置文件的名称
$filename = '8.iso';

$file = fopen($url, "rb");
header('Content-Description: File Transfer');
Header('Content-type: application/octet-stream');
header('Content-Transfer-Encoding: binary');
Header('Accept-Ranges: bytes');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Expires: 0');
header('Pragma: public');
Header('Content-Disposition: attachment; filename=' . $filename);
$contents = "";
while (!feof($file))
{
    echo fread($file, 8192);
}
fclose($file);

提示:适合小文件下载,大文件传输时间长,web服务器容易断开。另外的方案是通过php分片下载到服务器本地,然后再下载,具体代码正在实现。

扫描二维码推送至手机访问。

版权声明:本文由高久峰个人博客发布,如需转载请注明出处。

本文链接:https://blog.20230611.cn/post/107.html

分享给朋友:

“php代理下载,php代下载文件,php下载远程文件,php远程文件下载” 的相关文章

php scoket,php webscoket,php webscoket 服务器

php scoket,php webscoket,php webscoket 服务器

项目需要使用websocket推送最新订单,客户服务器非linux不支持swoole,因此使用原生,直接上代码(1).PHP服务端<?php ini_set('error_reporting', E_ALL ^ E_NOTICE); ini_set...

php创建webservice,php搭建webservice,php编写webservice

php创建webservice,php搭建webservice,php编写webservice

第一步:服务端文件<?php $wsdlfile='webservice.wsdl'; ini_set('soap.wsdl_cache_enabled','0');    //关闭WSDL缓存 //001...

php异步执行,php后台运行,如何在windows下让php后台运行

php异步执行,php后台运行,如何在windows下让php后台运行

如果想在windows中执行php,并且让php脚本在后台运行,可以用下面的cmd命令start /b php  D:\wwwroot\default\demo1\run.php例如上面的命令意思后台运行run.php,如果想用php编写异步代码: ...

swoole中的worker_num和task_worker_num

swoole中的worker_num和task_worker_num

(1)swoole启动的主进程是master进程负责全局管理,然后master进程会再fork一个manager进程。(2)manager进程开始统一管理进程创建回收管理。(3)manager进程根据设置的worker_num和task_worker_num来创建work进程和task进程因此启动s...

php mcrypt扩展被废弃的解决方案

php mcrypt扩展被废弃的解决方案

使用openssl扩展对应替换mcrypt的函数,(比较麻烦,但是openssl是未来趋势)在新版php中编译mcrypt扩展使用一个纯php代码实现的mcrypt扩展库,git地址为https://github.com/phpseclib/mcrypt_compat,每个mcrypt的方法都已经实...