下载与php与标题不起作用的IE8 [英] Download with php with headers do not work on IE8

查看:102
本文介绍了下载与php与标题不起作用的IE8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $ filename =assets.xls我正在尝试下载一个使用php头文件生成的excel文件; 
header('Content-Type:application / vnd.ms-excel');
header(Content-Disposition:attachment; filename = $ filename);
header('Cache-Control:max-age = 0');
$ objWriter = PHPExcel_IOFactory :: createWriter($ objPHPExcel,'Excel5');
$ objWriter-> save('php:// output');

但是这不适用于IE8(但是在其他一些与IE8相关的电脑上! )。 IE8尝试下载export.php文件而不是assets.xls。任何想法为什么IE8这样做?

解决方案

尝试正确格式化标题根据HTTP规范,空格在之间; filename 并引用文件名:

  header('Content-处理:attachment; filename ='。$ filename。''); 


I am trying to download a excel file generated on the fly with php headers:

$filename = "assets.xls";
header('Content-Type: application/vnd.ms-excel');
header("Content-Disposition: attachment;filename=$filename");
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');

But this does not work on IE8 (but on some other pc with IE8 works???!!). IE8 tries to download the export.php file instead of assets.xls. Any idea why IE8 do this?

解决方案

Try to format the header correctly as per the HTTP spec with a space between ; and filename and quotes around the filename:

header('Content-Disposition: attachment; filename="' . $filename . '"');

这篇关于下载与php与标题不起作用的IE8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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