note 58043 deleted from function.header by tularis
| From: | tularis@php.net | Date: | Fri, 20 Apr 2007 14:43:20 +0000 |
| Subject: | note 58043 deleted from function.header by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-125656@lists.php.net to get a copy of this message | ||
Note Submitter: hsmcdonald at gmail dot com
----
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..