PHP xlsx header

廉价感情. 提交于 2019-12-01 16:45:20

Depends on your browsers so many things can cause such behavior such as Content-length , Cache-Control etc

Also Change

Content-type to Content-Type

Content-disposition to Content-Disposition

Try

$file = "myfile.xlsx" ;
header('Content-Disposition: attachment; filename=' . $file );
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Length: ' . filesize($file));
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
readfile('myfile.xlsx');

Depending on your web browser, the filename may not be saving fully with periods. If the filename is incomplete, you can try and replace this header:

header('Content-disposition: attachment; filename=myfile.xlsx');

with

$filename = "myfile.xlsx";
header('Content-Disposition: attachment; filename="' . $filename . '"');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save($filename);
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Length: ' . filesize($filename));
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
readfile($filename);
return;

This solution works for me, but when i'm trying to open downloaded file i'm getting an error. For .pdf file is just empty.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!