473,385 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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($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
anything.

Please feel free to email me at go***@myrealbox.com with your
suggestions...and 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 :)

Jul 17 '05 #1
2 1788
On 18 Apr 2005 13:03:08 -0700, "pbay" <pa********@sympatico.ca> wrote:
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).
That's a UTF-8 encoded Byte Order Mark (BOM).
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
anything.


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 / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2
Notepad is the prime suspect.

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Kristian Nybo | last post by:
Hi, I'm writing a simple image file exporter as part of a school project. To implement my image format of choice I need to work with big-endian bytes, where 'byte' of course means '8 bits', not...
4
by: martin | last post by:
Hi, I am copying an xml file like so. Dim xmlDoc As New XmlDocument xmlDoc.Load("C:\Program Files\Templates\message.msg") Console.WriteLine("Tmaplate loaded") xmlDoc.Save("C:\Program...
13
by: Shailesh Humbad | last post by:
Here is an advanced PHP question. Can anyone think of a way to detect the number of bytes written to output when a script is aborted? I am sending a large file to the client, and I want to record...
2
by: fineman | last post by:
Hi all, I want to get a 64bit(8 bytes) Encrypt result use DES class in the VS2005. Though I encrypt data is 64bit(8 bytes), but DES return encrypt result that always is 128bit(16 bytes), I don't...
18
by: p.lavarre | last post by:
Can Python not express the idea of a three-byte int? For instance, in the working example below, can we somehow collapse the three calls of struct.pack into one? 08 12 34 56 80 00 I ask...
11
by: Freddy Coal | last post by:
Hi, I'm trying to read a binary file of 2411 Bytes, I would like load all the file in a String. I make this function for make that: '-------------------------- Public Shared Function...
9
by: fscked | last post by:
Anyone have an idea of what I might do to fix this? I have googled adn can only find some random conversations about it that doesn't make sense to me. I am basically reading in a csv file to...
9
by: vineeth | last post by:
Hello all, I have come across a weird problem, I need to determine the amount of bytes read from a file, but couldn't figure it out , My program does this : __ file = open("somefile") data =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.