|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
I'm tring to run a php app on php 5.2.6 / apache 2.2.9 / windows 2003. the problem happanes when I try to download a file like this: while(!feof($fp)) { echo fread($fp, 8192); flush(); } fclose($fp); It sends additional tree bytes of utf-8 BOM (EF BB BF) and it corrupts the file.. I checked the files and they doesn't include BOM. I changed my code to this: $bom = fread($fp, 3); if ($bom != b"\xEF\xBB\xBF") rewind($fp, 0); while(!feof($fp)) { echo fread($fp, 8192); flush(); } fclose($fp); but the problem still exists and it seems that php /mbstring adds BOM to all content transfers even binary files! is there anyway to strip BOM from php output on the fly ? Best Regards , Mehdy Mohajery --- |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Oct 11, 6:38am, Mehdy Mohajery <biho...@gmail.com> wrote:
> if ($bom != b"\xEF\xBB\xBF") Is this (what I assume is) binary string syntax (b"string") documented anywhere? > it seems that php /mbstring adds BOM to all content transfers even binaryfiles! Check the config vars listed here http://www.php.net/manual/en/mbstring.configuration.php .. "mbstring.http_output" seems like something that could cause such behavior. Before all your output do ob_start(); and then $out = ob_get_contents(); at the end. Then analyze $out. Here's a quick function to maybe make this easier: http://www.php.net/manual/en/languag...ring.php#86044 echo htmlspecialchars(doubleQuote($out)); Though the mbstring.http_output might work a layer above all that. Steve |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Hi Steve ,
I added o ob_start(); /ob_get_contents();/ htmlspecialchars and I checked the buffer , there is no BOM there and It seems to be added in another layer. setting mbstring.http_output = pass ; looks promissing but it didn't fix. the interesting point is that I send this headers: header("Content-Disposition: attachment; filename=\"". $_downloaditem["filename"] ."\""); header("Content-Transfer-Encoding: binary"); header('Pragma: no-cache'); header ('Cache-Control: no-cache, must-revalidate'); header('Expires: 0'); header('Accept-Ranges: bytes'); header('Content-Type: application/force-download'); when I change tha last line to : header('Content-Type: application/octet-stream'); it strips BOM from .zip and .pdf files but not .rar files. Thanks ![]() Mehdy Mohajery -- |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Oct 12, 12:11am, Mehdy Mohajery <biho...@gmail.com> wrote:
> header('Content-Type: application/octet-stream'); > it strips BOM from .zip and .pdf files but not .rar files. Strange. Is this behavior identical in all browsers? Have you looked at the raw HTTP output with a proxy like Fiddler (it has a hex viewer so you might be able to verify the BOM)? If you're on Windows Fiddler works for IE and Safari without any configuration. Steve |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Hi,
this behavior is identical in Firefox, Opera and Internet Explore. I checked the sessions fiddler's hex viewer and I can see "EF BB BF" in all downloads, when the downloaded file is .pdf or .zip , the browser ignores the BOM but for other files, it will be saved inside the downloaded file. seems like a bug in in mbstring handler. when I disable mbstring I've got no problems. Thanks , Mehdy ---- |
|
![]() |
| Outils de la discussion | |
|
|