I am doing some work on a website that has a secure area accessible to users only after they are logged in. In this area there is a page with links to pdf documents that can be downloaded. Physical documents are located outside the root directory of the website. Links to PDF documents look something like this:
?
index.php page = safe zone / loading & amp; file = protected.pdf
Which does the following (note: I know that this is a way to force the download, not open the file inside the browser):
// check security, get filename from request, prefix document download directory and check for file existance then... header('Content-Type: application/pdf'); header('Content-Disposition: attachment; filename="' . basename($file) . '"'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($file)); header('Connection: Close'); set_time_limit(0); readfile($file);
This works well, but in Firefox 3 and Internet Explorer 7 (I have not tested with any other browser) it will not open this file inside the browser, they both show the download dialog (as expected). If I select Open rather than Save, the document loads and Adobe Reader launches outside the browser to render the document.
The problem is downloading the file inside the browser and having the correct default file name when saving.
I would like to open the document in a browser. One way to do this is to use the heading "Content-Disposition: inline;" but that means that I cannot specify the file name (because the browser seems to be ignored by the browser). The problem with this is when I save the document, the default name is the name of the URL, not the name of the pdf document file:
http___example.com_index.php_page=secure_area_download&file=protected.pdf
How can I get Firefox and Internet Explorer to open the document inside the browser and provide the correct default filename for saving?
security browser file download inline
Stacey Richards Dec 19 '08 at 19:07 2008-12-19 19:07
source share