【问题标题】:php download excel filephp下载excel文件
【发布时间】:2020-01-13 15:12:01
【问题描述】:

我编写php代码下载excel文件,当我在本地主机上测试一切正常,文件可以打开,但是当我去我的服务器并测试代码时,文件不再可读。这是我的代码

$file = basename($path);

if(file_exists($path)){

        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: private",false);
        header("Content-Description: File Transfer");
        header("Content-Disposition: attachment; filename=\"$file\"");
        header("Content-Type:  application/vnd.ms-excel");
        header("Content-Transfer-Encoding: binary");
        header("Content-Length: ".filesize($path));
        readfile($path);
      exit;
}

对于环境,我在本地使用 PHP 版本 7.2.19,在我的服务器中使用 7.0.33,我尝试了所有我找到但没有工作的内容类型。

【问题讨论】:

    标签: php excel apache http-headers


    【解决方案1】:
    ob_clean();
    

    将该代码放在所有标头声明之前。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-18
      • 2012-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-01
      相关资源
      最近更新 更多