PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > php 5.2.6 / apache 2.2.9 / windows 2003 / mbstring puts BOM on binaryfiles!
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
php 5.2.6 / apache 2.2.9 / windows 2003 / mbstring puts BOM on binaryfiles!

Réponse
 
LinkBack Outils de la discussion
Vieux 11/10/2008, 12h38   #1
Mehdy Mohajery
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut php 5.2.6 / apache 2.2.9 / windows 2003 / mbstring puts BOM on binaryfiles!

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
---
  Réponse avec citation
Vieux 11/10/2008, 14h57   #2
mrclay
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: php 5.2.6 / apache 2.2.9 / windows 2003 / mbstring puts BOM onbinary files!

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
  Réponse avec citation
Vieux 12/10/2008, 06h11   #3
Mehdy Mohajery
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: php 5.2.6 / apache 2.2.9 / windows 2003 / mbstring puts BOM onbinary files!

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
--








  Réponse avec citation
Vieux 13/10/2008, 13h51   #4
mrclay
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: php 5.2.6 / apache 2.2.9 / windows 2003 / mbstring puts BOM onbinary files!

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
  Réponse avec citation
Vieux 14/10/2008, 00h06   #5
Mehdy Mohajery
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: php 5.2.6 / apache 2.2.9 / windows 2003 / mbstring puts BOM onbinary files!

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
----




  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 21h08.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10171 seconds with 13 queries