Three bytes prepended to data

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hi everyone,

I'm experiencing a problem with PHP that doesn't seem to have any
documentation related to it. I hope it's a simple error on my part :)

Basically, I'm loading a SWF (Macromedia Flash) file via a PHP file.

Here's a copy of this tiny script:

    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\r\n");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT\r\n");
    header("Content-Type:  application/x-shockwave-flash;
    header("Content-Length: ".filesize($file)."\r\n");
    $fHandle = fopen($file, "rb");
    $content=fread($fHandle, filesize($file));
    echo $content
    fclose ($fHandle);

The problem is that for some reason there are an extra three bytes of
data that are prepended to the beginning of this file.

The beginning of the file should begin: FWS
But instead begins: FWS

(sorry if you can't see it correctly...basically there are three extra
characters before the FWS).

Initially I though it might be part of the file so I stripped the first
three characters off. However, these extra three bytes still appear and
instead the FWS was removed. Could this be added by the web server
before sending out?

I thought maybe the data in the file was UTF-8 encoded (and that this
was some sort of UTF-8 header) so I tried decoding it (utf8-decode),
and when that didn't work I tried decoding and re-encoding. I tried
this along with a combination of setting UTF-8 and ISO as the charset
in the header. I tried setting the multibyte string settings to work
directly with the ISO charset (mb_internal_encoding and mb_http_output)
as well as varying combinations of ISO and UTF-8.

My findings thus far seem to indicate that if the string is treated as
UTF-8 encoded by the browser, the extra three bytes are removed but the
data is changed (a few bytes are added and/or changed at various
positions in the file).

One other thing that supports all of this is that the file size
increases by three bytes exactly when I load the data from the script
(presumably from this problem). When I load the SWF directly, it's
three bytes smaller.

I had similar problems when loading XML data except in that case the
file was prepended by three bytes and then another three bytes were
added to the end.

If anyone has had any experience with this I would greatly appreciate
your help as I've scoured the help documentation and not found

Please feel free to email me at with your
suggestions...and BIG THANKS in advance.

   Patrick Bay

P.S. This is something that needs to happen through the script, in case
that was a suggestion :)

Re: Three bytes prepended to data

Quoted text here. Click to load it

 That's a UTF-8 encoded Byte Order Mark (BOM).

Quoted text here. Click to load it

 What are you editing the _PHP_ file with? That would be the prime suspect. It
probably thinks the file is UTF-8 and so prepends a BOM.

< Space: disk usage analysis tool

Re: Three bytes prepended to data

Notepad is the prime suspect.

Site Timeline