Sending files to the user...?
| From: | Alan McFarlane | Date: | Tue, 05 Feb 2002 12:30:53 +0000 |
| Subject: | Sending files to the user...? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-83582@lists.php.net to get a copy of this message | ||
The problem:
How to I send a file to the user? Sounds simple but, assume I have a 'daily
report' option from my main web page. When the user clicks on it, they are
taken to the file 'generate_report.php' (sample included).
Now, this code should generate the report, compress it if required and send
it ot the user - i.e. a dialog box opens asking the user to open/save/run
the incoming file.
Question is, how? - I've toyed with Content-Disposition but I'm not sure of
any reference materials for this. (Perhaps someone knows the RFC)
The code:
<?php
/* file: generate_report.php */
// build the report
$report = "<xml...>"; /* basically an xml document
// compress if possible
if (extension_loaded("zlib") && (strlen($report) > 1024))
{
$report = gzcompress($report);
$compress = true;
}
else
{
$compressed = false;
}
$length = strlen($report); // I presume this can handle binary data
// header(" something ");
?>