Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
File download problem - extra bytes
Old 12-08-2009, 04:19 PM File download problem - extra bytes
Novice Talker

Posts: 12
Trades: 0
Hello,

I have the code below which simply downloads a test file. It works fine if I run it as it is. However if I put this code inside a more complex page then the downloaded file contains some extra characters.

I mean to output should be a simple 1 byte file which contains a letter 'a'. However if I built in this code then the downloaded file will be 6 byte long as there are some hidden characters before 'a'.

Maybe it is relevant to character encoding but I have no idea how to fix it.

Code:
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header("Content-Disposition: attachment;filename=test.txt"); 
        header("Content-Transfer-Encoding: binary ");
        
        echo "a";
Any idea how can I eliminate the extra bytes?

Thanks in advance!
elmu is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-08-2009, 05:10 PM Re: File download problem - extra bytes
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
If you use something like the firebug net tab, and look at the answered headers from the server, what do you see ?

What is the encoding of the php file too ?
It may be that your PHP file contains a BOM (Byte Order Mark). It's a specific encoding indication that is put at the beginning of a file, but most of the time hidden to you by the editors, as they just use it to get the file encoding.

You might be able to see it if you use an hex editor, but I cannot say for sure.
Maybe something like scite , if you enable the display of the white spaces, will show it to you, I don't know.
scite: http://prdownloads.sourceforge.net/s...1.zip?download

It's been so long I have not been exposed to a BOM, that I honestly don't remember how to see it.
And I'm running a Linux desktop anyway, so...

On windows, I've found a link about a BOM detector, written in .net: http://www.wiso.cz/2007/08/08/bomdet...-bom-in-files/

Maybe it can tell you if your file does have a BOM.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 12-08-2009, 06:27 PM Re: File download problem - extra bytes
Novice Talker

Posts: 12
Trades: 0
Problem solved.
There were some space and new line character after the closing php tag in a file which was imported before the download.
elmu is offline
Reply With Quote
View Public Profile
 
Old 12-10-2009, 12:55 PM Re: File download problem - extra bytes
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Why do you use three different content-types in one response? Anyway only the last one will be sent to client.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to File download problem - extra bytes
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31269 seconds with 12 queries