note 46454 added to function.header
| From: | obren at mail dot com | Date: | Tue, 12 Oct 2004 09:31:26 +0000 |
| Subject: | note 46454 added to function.header | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78398@lists.php.net to get a copy of this message | ||
May save some time and nerves to somebody...
I have the following fragment of code in my PHP script:
...
header('Cache-Control: no-cache, must-revalidate');
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Length: '.filesize($fname));
header('Content-Disposition: attachment; filename='.basename($fname));
$f = fopen($fname, 'rb');
fpassthru($f);
fclose($f);
...
But, this produces corrupted binary files on receiving side. After hours of headbanging, I found
that the reson are whitespaces around one <?php ... ?> fragment!
<form ... action="<?=$_SERVER["PHP_SELF"]?>"> <?php ...
Notice that "whitespace" between <form> tag and <?php> tag!
Strange, but once I removed the space, the problem with corrupted files dissapeared. Looks like
space character somehow remained in the output buffer and got transfered as the content of binary
file.
Regards, Dragan
----
Manual Page -- http://www.php.net/manual/en/function.header.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46454
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46454&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46454&report=yes
Search -- http://master.php.net/manage/user-notes.php