Weblog of Nazly Ahmed
I had a serious problem today while I was at work. I was working on this project that involved some important pdf documents to be downloaded via https. I wrote the code to read the pdf file which is located outside the webroot and will prompt the download window to the user. This worked fine in Mozilla Firefox which is my primary browser. Later when I checked the script in IE, instead of the filename of the pdf file to be downloaded, it prompted the filename of the PHP script that does the download process.
After breaking my head on this it was Paul (AKA Postalcow @ Codewalkers.com) who rescued me. He mentioned the fact that MSIE does not allow to cache a secure document but it needs to read the document from cache. And also gave this info from the Microsoft website
After that I managed to get it sorted by adding this header to my script
1 2 3
<?php header("Pragma: cache"); ?>
Finally my script looked like this
1 2 3 4 5 6 7 8 9 10
<?php $fileName="myfile.pdf"; $pathToFile = "/path/to/file/"; $fileName = ereg_replace(".php","",$fileName); header("Pragma: cache");//This solved the problem header("Content-type: application/pdf"); header("Content-Disposition: attachment; filename=\"$fileName\""); readfile($pathToFile.$fileName); exit; ?>
Had a tough time lately as there was no Internet access for nearly three days. Life is really hard without connecting to the rest of the world.
The problem was due to the damage caused by a ship to the Internatinal Submarine Cable System and the connectivity to the Global Internet was lost. Anyway things seems to be undercontrol now.