note 62859 added to function.header

From: Date: Sat, 11 Mar 2006 01:57:39 +0000
Subject: note 62859 added to function.header
Groups: php.notes 
Request: Send a blank email to php-notes+get-105254@lists.php.net to get a copy of this message
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. ---- Server IP: 84.18.202.180 Probable Submitter: 88.111.183.28 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.header.php Edit -- http://master.php.net/note/edit/62859 Del: integrated -- http://master.php.net/note/delete/62859/integrated Del: useless -- http://master.php.net/note/delete/62859/useless Del: bad code -- http://master.php.net/note/delete/62859/bad+code Del: spam -- http://master.php.net/note/delete/62859/spam Del: non-english -- http://master.php.net/note/delete/62859/non-english Del: in docs -- http://master.php.net/note/delete/62859/in+docs Del: other reasons-- http://master.php.net/note/delete/62859 Reject -- http://master.php.net/note/reject/62859 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#105254) next »