PHP PDF force download
Posted: Tue Aug 24, 2004 12:12 pm
I'm having problems with downloading served PDFs with IE. With Firefox everything works beutifully. The PDFs are in a non-public directory which is accessable to PHP. I have tried all kinds of different headers and googled until my eyes burned but could not find an answer to this. This is the code I'm using:
I've tried stripping all but the necessary headers, rearranging them to suit IE but nothing. The purpose of this script is to make sure the user is authenticated and known before giving them a file(that portion has been left out). These pdfs can not go into a public directory. Any help would be very appreciated.
Code: Select all
$down = $_GETї'd'];
$file = "/home/et/down" . $down;
$doc_name = eregi_replace("ї/]+їA-Za-z]+ї/]", "", $down);
#echo "docname: " . $doc_name;
if (!$fsize=@filesize($file)) {
die("There has been an error retrieving this file.");
}
header("Accept-Ranges: Bytes");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=" . $doc_name);
header("Content-Description: File Transfer");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $fsize);
$fp = fopen($file, 'r');
$pdf_buffer = fread($fp, $fsize);
fclose ($fp);
print $pdf_buffer;
exit();