我从服务器下载文件,但下载后 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/