我使用以下代码通过PHP向访问者([link][1])发送PDF:
session_start();
$fileName = '0-1.pdf';
$file = '../invoices/'. $fileName;
if (file_exists($file)) {
$size = filesize($file);
header('Content-Disposition: attachment; filename="'. $fileName .'"');
header('Content-Length: '.$size);
header('Content-type: application/octetstream');
#header('Content-type: application/pdf');
echo file_get_contents($file);
}
它在Chrome, FF和ie9上运行良好,但在ie8上失败。
它失败的原因是
session_start();
如果我把它去掉,它也会在ie8中工作。
不幸的是,我需要这个会话。因为通过PHP传递PDF的全部原因是执行身份验证检查。所以我需要会话ID来检查当前用户是否被允许访问PDF。
任何想法如何让下载工作在ie8与头session_start()发送?
刚刚找到解决办法了
在session_start()
之后,我必须设置这些标头以使其与IE 8一起工作:
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
奇怪的行为……但它现在工作:-)