PHP - Excel 文件下载

标签 php

我从服务器下载文件,但下载后 Excel 或 Word 文件已损坏。 Pdf、jpg 等都可以。

ob_clean();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: ").$att->getType();
header("Content-Disposition: attachment; filename=" . basename($att->getName()));  
header("Content-Transfer-Encoding: binary");
header("Content-Description: File Transfer");
readfile($path);

我拥有的 Excel 内容类型 - application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

最佳答案

改变一下

header("Content-Type: ").$att->getType();

header("Content-Type: ".$att->getType());

您发送内容类型为空的文件...

关于PHP - Excel 文件下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65467624/

相关文章:

php - 模式、PHP、ORM

php - 检查类别是否有父级

php - 通过 php 表单发送电子邮件文件

php - html表单数组如何存储到不包括空元素的php数组中

PHP apc/apcu 缓存不保留中间结果而 shmop 保留,为什么?

php - rename() 和 unlink() 是异步函数吗?

php - 撇号导致已通过 mysqli_real_escape_string & trim 运行的表项的行重复出现错误

php - 将版本从 php 7.0 更改为 7.1 不起作用

php - 在codeigniter php中根据性别显示不同的前缀

javascript - AJAX 调用不调用提醒