【发布时间】: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