Three bytes prepended to data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pbay

    Three bytes prepended to data

    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:

    <?php
    $file="test.swf ";
    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;
    charset=ISO-8859-1");
    header("Content-Length: ".filesize($fil e)."\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...bas ically 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_en coding 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
    anything.

    Please feel free to email me at gokid@myrealbox .com with your
    suggestions...a nd BIG THANKS in advance.

    Sincerely,
    Patrick Bay

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

  • Andy Hassall

    #2
    Re: Three bytes prepended to data

    On 18 Apr 2005 13:03:08 -0700, "pbay" <patrickbay@sym patico.ca> wrote:
    [color=blue]
    >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Õ[/color]
    [color=blue]
    >But instead begins: FWSÕ[/color]
    [color=blue]
    >
    >(sorry if you can't see it correctly...bas ically there are three extra
    >characters before the FWS).[/color]

    That's a UTF-8 encoded Byte Order Mark (BOM).
    [color=blue]
    >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_en coding 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
    >anything.[/color]

    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.

    --
    Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

    Comment

    • Chung Leong

      #3
      Re: Three bytes prepended to data

      Notepad is the prime suspect.

      Comment

      Working...