I write a simple php to load some binary data from DB then output to client.
$sql="select FightPlayEnd from ZMTXLogic.FightLog where ID=".addslashes($id);
$result=$db->query($sql);
if($db->num_rows($result)>0)
{
$row = mysql_fetch_assoc($result);
$nByteCount = mb_strlen($row["FightPlayEnd"], '8bit');
//echo $nByteCount;
header("Content-type:application/octet-stream");
header("Accept-Ranges:bytes");
header("Accept-Length:".$nByteCount);
header("Content-Disposition:attachment;filename=FightPlayEnd.bin");
header( "Content-type: application/octet-stream");
echo $row["FightPlayEnd"];
}
The problem is the data got from IE is not same as original binary data but added
EF BB BF(view in UltraEdit) at the header and 0D 0A 0D 0A at the end. What is wrong with it?
0D 0A 0D 0Ais just\r\n\r\n, that is, two linebreaks.EE BB BFis a byte order mark. It signals UTF-8 encoding.Edit (see comments):
Your script might be outputting more than it should (particularly those
\r\n\r\n).You need to clean the output buffer before you start outputting the data (
ob_clean()) and exit right after your echo.