Safari添加.html下载 [英] Safari adding .html to download

查看:263
本文介绍了Safari添加.html下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些功能,创建.xls文档(使用PHPexcel),然后发送到php://输出。然后用户下载它。

一切正常,除了mac os x上的safari添加了.html扩展名。

所以结果文件名为report.xls.html。内容是确定的,但对用户来说是令人讨厌的。



我如何解决?



我的代码的一部分:

  $ filename ='report.xls'; 

header('Content-Description:File Transfer');
header('Content-Type:application / vnd.ms-excel');
header('Content-Disposition:attachment; filename ='。$ filename。'');
header('Content-Transfer-Encoding:binary');
header('Connection:Keep-Alive');
header('Expires:0');
header('Cache-Control:must-revalidate,post-check = 0,pre-check = 0');
header('Pragma:public');

$ objWriter = new PHPExcel_Writer_Excel5($ objPHPExcel);
$ objWriter-> save('php:// output');


解决方案

我有同样的问题



解决与退出;在脚本的末尾

  $ filename ='report.xls'; 
header('Content-Description:File Transfer');
header('Content-Type:application / vnd.ms-excel');
header('Content-Disposition:attachment; filename ='。$ filename。'');
header('Content-Transfer-Encoding:binary');
header('Connection:Keep-Alive');
header('Expires:0');
header('Cache-Control:must-revalidate,post-check = 0,pre-check = 0');
header('Pragma:public');

$ objWriter = new PHPExcel_Writer_Excel5($ objPHPExcel);
$ objWriter-> save('php:// output');
退出;


I have a little function, that creates .xls document(using PHPexcel) and then sends it to php://output. Then user download it.
Everything works fine, except that safari on mac os x adds .html extension for some reason.
So the resulted file is named report.xls.html. Content is ok, but it is annoying to the users.

How can I resolve this?

Here is part of my code:

$filename = 'report.xls';

header('Content-Description: File Transfer');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="'.$filename.'"'); 
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');

$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
$objWriter->save('php://output');

解决方案

I had the same problem

Resolved with exit; at the end of the script

$filename = 'report.xls';
header('Content-Description: File Transfer');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="'.$filename.'"'); 
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');

$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
$objWriter->save('php://output');
exit;

这篇关于Safari添加.html下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆