【发布时间】:2012-08-29 09:36:10
【问题描述】:
我有一个 PHP 脚本,它使用 PHPExcel 打开模板,从数据库查询中插入值,然后将结果返回给浏览器。它在 Firefox 中完美运行,但在 Internet Explorer (8) 中,当它尝试打开文件时,它会中断:
Internet Explorer 无法从 my.domain 下载 generate.php。
Internet Explorer 无法打开此 Internet 站点。这 请求的站点不可用或找不到。请试试 稍后再来。
我使用的代码(generate.php)如下:
// Open template
$xlRead = PHPExcel_IOFactory::createReader('Excel5');
$xl = $xlRead->load('Template.xls');
$xl->setActiveSheetIndex(0);
// Write data
$xl->getActiveSheet()->fromArray($dbOutput, null, 'A1');
// Output to browser
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename=MyReport.xls');
$xlWrite = PHPExcel_IOFactory::createWriter($xl, 'Excel5');
$xlWrite->save('php://output')
编辑 似乎这个问题只在 SSL 之后影响 IE。因此,这与几个类似的 SO 问题是相同的问题。人们的建议是调整标题,但到目前为止,我所看到的解决方案组合都没有奏效......
【问题讨论】:
-
也许这个答案可以帮助你stackoverflow.com/a/6065779/1503552
-
尝试在
content-Disposition标头中的attachment之后添加一个空格。 -
添加空格没有任何效果。关闭 SSL 解决了这个问题,所以它肯定与这个链接的问题有关:但是,该查询的解决方案也没有为我解决它(我需要保持 SSL 开启)。
标签: php internet-explorer phpexcel