473,597 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 go***@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 :)

Jul 17 '05 #1
2 1800
On 18 Apr 2005 13:03:08 -0700, "pbay" <pa********@sym patico.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...bas ically 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_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.


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.andyhsoftwa re.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
3266
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 'sizeof(char)'. It seems that I could use bitset<8> to represent a byte in my code --- if you have a better suggestion, I welcome it --- but that still leaves me with the question of how to write those bitsets to an image file as big-endian bytes...
4
2241
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 Files\Templates\copy.xml") Console.WriteLine("message saved")
13
2416
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 how many bytes are actually sent. I can detect abort of the script using a shutdown handler. In the shutdown handler, I tried ob_get_length, but it returns false. I tried to read the server's log file, but it is does not contain the...
2
3171
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 know why? How to get a 64bit(8 bytes) encrypt result using DES class in the VS2005?
18
7555
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 because I'm trying to refactor working code that is concise: 08 12 34 56 80 00
11
3578
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 Read_bin(ByVal ruta As String) Dim cadena As String = "" Dim dato As Array If File.Exists(ruta) = True Then
9
11366
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 create an xml and get this error. I don't see any empty values in any fields or anything...
9
3838
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 = file.read() print "bytes read ", len(data) ---
0
7886
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8272
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8035
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6688
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3886
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3927
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2404
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1494
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1238
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.