Output binary data by PHP without BOM

Normally, we use a file to handle binary data(image or text files), output the file direct with file handle by PHP or Nginx or Apache. It works fine.

When using PHP to handle the data of a binary file, we read out the content of a binary file then store it into Database, the content is always binary data. We use PHP to read out the data from Database, echo out to browser.

But the browser always show error, Image can not display correctly, neither binary text file can open well. After compare the original file and the output data, I found PHP always add the UTF-8 BOM at the very begging of the output binary data.

But there is no place to change this. I tried to modify mb code:

  • mb_internal_encoding(‘US-ASCII’);
  • mb_http_output(‘US-ASCII’);

Nothing changes after I add this before header and  output:

  • ob_clean();

Even it works well now, I do not why so.

The refer URL is HERE, comments are funny ;-D

Thanks Vurdalakov.

发布日期:

发表评论