【问题标题】:PHP How to download file tar.gz using download button?PHP 如何使用下载按钮下载文件 tar.gz?
【发布时间】:2017-03-05 20:31:03
【问题描述】:

我有这样的代码:

        header("Pragma: public", true);
        header("Expires: 0"); // set expiration time
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header('Content-type: application/rar');
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header('Content-Type: application/download');
        header('Content-Disposition: attachment; filename='.$fullname);
        header("Content-Transfer-Encoding: binary");
        header("Content-Length: " . filesize($fullname));
        $fp = fopen($fullname, "r");
        fpassthru($fp);
        fclose($fp);

根据以上代码,下载正在运行,但无法打开 tar.gz。 如何解决?可以下载 tar.gz 吗?

【问题讨论】:

标签: php


【解决方案1】:

GNU 压缩档案的内容类型是 application/x-gzip。 您应该使用下面的代码来设置内容类型

header('Content-type: application/x-gzip');

【讨论】:

  • 请详细说明原因,让您的回答明确,谢谢。
  • 希望我的改变足够
猜你喜欢
  • 2020-08-25
  • 2021-10-11
  • 1970-01-01
  • 2020-10-15
  • 1970-01-01
  • 2015-01-07
  • 2021-11-19
  • 1970-01-01
  • 2015-07-04
相关资源
最近更新 更多