php - 使用 PHP 下载远程文件时遇到问题(空 ZIP)
问题描述
我需要从 Web 服务(GET-request)下载一个 zip 文件(通过 PHP),然后将其传输给用户进行保存。我当前的代码如下所示:
download_file('http://remotesrv/getFile?username=username&userpassword=userpassword'); //remote service, that generate a file on the fly
function download_file($file) {
ob_clean();
header("Expires: 0");
header("Pragma: no-cache");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=\"file.zip\"; filename*=\"file.zip\"");
exit(readfile($file));
}
此代码在 Chrome 和 Opera 浏览器中运行良好,但在 Firefox、IE 和 Edge 中,它会下载一个空的零大小存档。告诉我一些解决问题的方法。提前谢谢,对不起我的英语:)
解决方案
推荐阅读
- reactjs - 使用循环反应上下文更新,但不适用于单个项目
- hyper-v - 安装并启用 Hyper-V
- python - 为什么对 numpy.float64 求幂返回 nan?
- c# - 在 Azure 容器实例中连接到 Web 套接字服务器时出现问题
- performance - Jenkins 和性能插件报告
- opencv - 如何在 Ubuntu 18.04 中为 python-opencv (4.1.2) 设置/安装/启用 DC1394 (libdc1394 v2.x) 后端?
- css - NavLink 没有按照 css 样式呈现子按钮
- java - 将 springboot 属性映射到 JAXB 命名空间
- c++ - QTableview 搜索
- java - 通过 Vaadin Grid 中的条目下载多个文件