Re: Downloading files - Plz hlp
| From: | Ernest E Vogelsinger | Date: | Mon, 24 Feb 2003 00:00:13 +0000 |
| Subject: | Re: Downloading files - Plz hlp | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-136792@lists.php.net to get a copy of this message | ||
At 00:52 24.02.2003, Anthony Rodriguez said:
--------------------[snip]--------------------
>In PHP, is there a way to allow the user to download a demo file (e.g.:
>sample.exe) to their computer? And, then, automatically return to the Web
>site?
--------------------[snip]--------------------
A couple of. Generally a browser will not leave the current page when
starting a file download - it simply remains on the page.
As for your question:
1) Generate a link to the exe file within your HTML output:
echo '<a href="sample.exe">Get the sample.exe file</a>';
2) If you don't have a "file" but need to construct it on the fly (or it is
not directly accessible from within your webserver), simply echo out the
data after sending an appropriate MIME headers.
Assuming you have the file contents in a variable called "$export":
header('Content-Type: application/octet-stream');
header('Content-Length: ' . strlen($export));
header('Content-Disposition: attachment;filename="sample.exe"');
echo $export;
exit();
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/