如何使用php导出XLS文件并提示下载另存

PHP导出Excel格式文件(xls),只需给PHP文件加一个文件头,filename 就是导出的xls文件名,当你点击这个文件的URL时,就会提示你下载xls文件了

header(Pragma: public);
header(Expires: 0);
header(Cache-Control: must-revalidate, post-check=0, pre-check=0);
header(Content-Type: application/force-download);
header(Content-Type: application/download);
header(Content-Disposition: attachment;filename=$filename);
header(Content-Transfer-Encoding: binary );

或者

header(Pragma: public);
header(Expires: 0);
header(Content-Type: application/force-download);
header(Content-Type: application/download);
header(Content-Disposition: attachment;filename=$fn);
header(Content-Transfer-Encoding: binary );//二进制

相关日志


如果你觉得这篇文章不错,你可以 给我留个回复订阅它。无论如何,谢谢你的支持!

评论

Hi, cool post. I have been thinking about this topic,so thanks for posting. I’ll probably be subscribing to your blog. Keep up the good work

发表评论

(必填)

(必填)