note 24188 added to function.header
| From: | lists at darkcore dot net | Date: | Thu, 08 Aug 2002 18:24:46 +0000 |
| Subject: | note 24188 added to function.header | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-34546@lists.php.net to get a copy of this message | ||
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.
--
http://www.php.net/manual/en/function.header.php
http://master.php.net/manage/user-notes.php?action=edit+24188
http://master.php.net/manage/user-notes.php?action=delete+24188
http://master.php.net/manage/user-notes.php?action=reject+24188