note 58043 added to function.header

From: Date: Sat, 22 Oct 2005 05:39:12 +0000
Subject: note 58043 added to function.header
Groups: php.notes 
Request: Send a blank email to php-notes+get-97401@lists.php.net to get a copy of this message
I had a special situation where I wanted to have a "Download" button on a PHP script, and have the the script post to itself to call a special block of code to initiate download of dynamically created content (rather than display contents of a file). I was running in circles trying to get IE SP1, SP2 and Firefox on Win98, 2000, and XP to all work where the download prompt is displayed AND the filename is controlled by me and not the browser. I found the following headers from a form that seem to work in all cases.: <?php // load content into var $filecontent="Some text/code im creating in the script"; $downloadfile="somefile.txt"; header("Content-disposition: attachment; filename=$downloadfile"); header("Content-Type: application/force-download"); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".strlen($filecontent)); header("Pragma: no-cache"); header("Expires: 0"); ?> Hope this helps someone.. ---- Manual Page -- http://www.php.net/manual/en/function.header.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58043 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58043&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58043&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58043&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58043&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58043&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58043&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58043&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58043&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#97401) next »