【问题标题】:How to download .zip file using PHP如何使用 PHP 下载 .zip 文件
【发布时间】:2017-10-20 08:24:00
【问题描述】:

我的网站在http://domain1.com,我想从另一个域http://domain2.com/uploads/data.zip 下载一些.zip 文件,但没有下载并显示302 移动临时错误。我正在使用 cURL 代码。

header('Access-Control-Allow-Origin: http://www.domain2.com');
header('Content-Length: '.filesize($response));  
header('Content-Type: application/zip');
header('Content-Transfer-Encoding: Binary');  
header("Content-Disposition: attachment; filename=my.zip");
//readfile($response);
header("Location:$response");

【问题讨论】:

标签: php curl


【解决方案1】:

只需在项目根目录创建一个 php 文件。比如“test.php”

现在在“test.php”文件中添加以下代码。

file_put_contents("zipname.zip", fopen("http://domain2.com/uploads/data.zip", 'r'));

这是使用 php 下载文件的最快、最简单的方法。

更多详情见下文

https://thecodingstuff.com/php-download-archive-file-from-url/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 2017-07-10
    • 1970-01-01
    • 2015-07-21
    • 2013-11-02
    相关资源
    最近更新 更多