I use this code to send an PDF through PHP to the visitor ([link][1]):
session_start();
$fileName = '0-1.pdf';
$file =开发者_如何学Python '../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);
}
It works well on Chrome, FF and IE 9 but fails on IE 8.
The reason it fails is
session_start();
If I leave it out, it will work in IE 8 as well.
Unfortunately I need the session. Since the whole reason for passing the PDF through PHP is to perform an authentication check. So I need the session ID to check if the current user is allowed to access the PDF.
Any ideas how to get the download to work in IE 8 with the headers session_start() sends?
Just found the solution.
Aftter session_start()
I have to set theese headers to get it to work with IE 8:
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
Strange behaviour... But it works now :-)
精彩评论