Re: Downloading a .txt file...

From: Date: Wed, 18 Oct 2000 12:28:57 +0000
Subject: Re: Downloading a .txt file...
References: 1  Groups: php.pear 
Request: Send a blank email to php-pear+get-406@lists.php.net to get a copy of this message
Edward Wong wrote: > Can anyone provide a better solution? I had a similar problem. I am providing pdf files for download, but I don't want to start the pdf viewer (acrobat or something similar) on the client side but rather save to file. I solved it by pointing from the link to another php page (download.php) instead of the real file: <a href="download.php">Download</a> download.php sends an extra header first and then the contents of the desired file. It looks like this: <?php // the name of the desired file for download is passed as // $filename (parameter, hidden form variable or session data) // most browsers will present a "Save As..." box for binaries header("Content-Type: application/octet-stream"); // suggest a file name in the "Save As..." box header("Content-Disposition: inline; filename=$filename"); // read the file and send it readfile($filename); ?> Remember that you can't have any output (not even a single whitespace or newline) in download.php before sending the last header. HTH Steffen -- http://steffen-uhlig.de/

« previous php.pear (#406) next »