Top o' the morning to ya.
Okay, so I have this download.php document that grabs files from an offline directory and passes them to users who authenticate properly.
I want the code to force a download dialog for for any file type that is not a PDF file, and I want PDF files to open in the browser.
$dir="C:/Program Files/Apache Group/Apache2/protected_files/ddap/"; //this is the "offline" directory in which the protected files are stored
if (isset($_REQUEST["file"])) { //checks to see if a file name was specified in the referring URL
$file=$dir . $_REQUEST["file"]; //if so, the $file variable is set to the name that was specified
if (file_exists("$file")) { //checks to see if the requested file actually exists, and if it does, it gets passed through to download
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: Binary");
header("Content-length: " . filesize($file));
header("Content-disposition: attachment; filename=" . basename($file) . "");
}
This works great for forcing the save dialog. Now, to make a PDF open in the browser, I need to determine if the file type is PDF or not (which I have done elsewhere). If the file type IS PDF, then I need to adjust the headers. The problem I'm having is that I can't seem to figure out the right information for the headers to get PDFs to open in the browser.
I tried this:
header("Content-type: application/pdf");
header("Content-Transfer-Encoding: Binary");
header("Content-length: " . filesize($file));
header("Content-disposition: inline; filename=" . basename($file) . "");
I must just be botching up those headers. Any ideas?
Thanks everyone!