note 62859 deleted from function.header by tularis

From: Date: Fri, 20 Apr 2007 14:35:42 +0000
Subject: note 62859 deleted from function.header by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-125642@lists.php.net to get a copy of this message
Note Submitter: vaughan montgomery ---- i was rackin my brains trying to figure out this IE bug.. when you hit the button to start the download, in IE you get the dialogue box asking you whether you want to save the file to disk or open it. non of the methods on this page seemed to work. after a lot of experimenting i found a solution which works in IE and firefox etc. i don't know about mac as i don't own one. the solution i used is > $mimeType = $download->getVar('filetype'); $filePath = '<your path to file>/'.trim($filename); if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); header("Pragma: public"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Transfer-Encoding: binary"); if(isset($mimeType)) { header("Content-Type: " . $mimeType); } header("Content-Disposition: attachment; filename=" . $filename); if(isset($mimeType) && strstr($mimeType, "text/")) { $fp = fopen($filePath, "r"); } else { $fp = fopen($filePath, "rb"); } fpassthru($fp); exit(); exit() is also required. note. you maybe asking why Content-Length is not added, that is because for some reason adding content-length stopped the actual file downloading correctly or opening. i don't know why, but as it worked without, i wasn't worried about not having it. please note tho, in the script, $download->getVar('filetype'); is a value that is pulled from a DB, the submission part of the script stores the mimetype in the db aswell, it was easier to do it that way, so adjust mimetype to whatever you require b4 you use it.. even pdf files download and also open aswell from the browser dialogue box in IE.

« previous php.notes (#125642) next »