note 24188 deleted from function.header by sniper
| From: | sniper@php.net | Date: | Sun, 07 Sep 2003 21:30:34 +0000 |
| Subject: | note 24188 deleted from function.header by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-55608@lists.php.net to get a copy of this message | ||
Note Submitter: lists@darkcore.net
----
Tips for sending files that are not in the web-path:
This may not be obvious to some but you should *NOT* use "include" to send a file because
it tries to do some parseing of the file and will error on characters not recognized by PHP.
'include' will work on text files (like word documets etc.) but not files with binary
content (like mp3, pdf, exe, etc).
For example, if you do the following:
$filename = "/var/private/acrobat.pdf";
header("Cache-control: private"); // fix for IE
header("Content-Type: application/octet-stream");
header("Content-Length: ".filesize($filename));
header("Content-Disposition: attachment; filename=acrobat.pdf");
include($filename); // ** WRONG **
You will likely get a plain text file that actually contans a bunch of PHP errors instead of the PDF
you wanted.
The correct method (as someone already posted) is to:
$fp = fopen($filename, 'r');
fpassthru($fp); // ** CORRECT **
fclose($fp);
As far as I know, this works 100% of the time.