note 62459 added to function.header

From: Date: Wed, 01 Mar 2006 07:36:58 +0000
Subject: note 62459 added to function.header
Groups: php.notes 
Request: Send a blank email to php-notes+get-104598@lists.php.net to get a copy of this message
One further note about forcing downloads in Internet Explorer. If the server has not yet issued an HTTP status code or has issued something other than a 200, you need to send HTTP/1.1 200 OK to the browser so that IE accepts the download without an error: header("HTTP/1.1 200 OK"); and/or header("Status: 200 OK"); I use a custom 404 error page to handle secure downloads. The user clicks on a link to a file such as 'http://mysite.com/user_files/file.txt'. That file does not exist, so my 404 page is invoked. It parses the address and if it finds the 'user_files' folder in the address, it attempts to open the file 'file.txt' from a non-web-accessible folder and sends it as a download instead of showing the 404 message. The problem I had was that IE always showed this error when you attempted to download or open the file: "Internet Explorer cannot download file.txt from mysite.com. Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later." The download worked fine in FireFox, and strangely, even worked fine on my local test server (Windows XP) in IE. But on the remote server (Apache) in IE, it threw the error above until I added the above status header(s). Now the code reads: header("HTTP/1.1 200 OK"); header("Status: 200 OK"); header('Content-Type: application/force-download'); header('Content-Disposition: attachment; filename="'.$downloadFile.'"'); header('Content-Length: '.filesize($downloadFilePath)); readfile($downloadFilePath); ---- Server IP: 216.194.113.175 Probable Submitter: 24.254.82.139 ---- 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/62459 Del: integrated -- http://master.php.net/note/delete/62459/integrated Del: useless -- http://master.php.net/note/delete/62459/useless Del: bad code -- http://master.php.net/note/delete/62459/bad+code Del: spam -- http://master.php.net/note/delete/62459/spam Del: non-english -- http://master.php.net/note/delete/62459/non-english Del: in docs -- http://master.php.net/note/delete/62459/in+docs Del: other reasons-- http://master.php.net/note/delete/62459 Reject -- http://master.php.net/note/reject/62459 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#104598) next »