PHP如何使用下载按钮下载文件tar.gz?

时间:2016-10-24 06:36:39

标签: php

我有这样的代码:

        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吗?

1 个答案:

答案 0 :(得分:0)

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

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