3

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?

0

1 Answer 1

4

0D 0A 0D 0A is just \r\n\r\n, that is, two linebreaks.

EE BB BF is 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.

Sign up to request clarification or add additional context in comments.

4 Comments

@Spark I would add to this, 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
@Ben Oh, you are perfectly right! Thank you very much! May be you can add a answer to my question, so I can accept you:)
@Spark Maybe you should give Dennis the answer credit for pointing us all in the right direction..
@Dennis Would you edit your answer and append what Ben said to it? So I can accept your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.