File download and spurious CR

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mbrampton
Forum Newbie
Posts: 9
Joined: Fri Mar 04, 2005 5:39 pm
Location: North Yorkshire

File download and spurious CR

Post by mbrampton »

It was a struggle to debug this, and all sorts of other things seemed more likely than the final explanation. Such is the way!

I support Remository, a file repository for the Mambo CMS. The download mechanism has been changed by me, and relies on sending headers followed by the file, simple transferred using readfile().

When the PHP routine just dropped off the end, this apparently resulted in IE and Firefox receiving files with a stray CR character on the end. Opera (my preferred browser) did not. The CR did no harm for most purposes, but upset PCLZIP, which is used for component installation in Mambo. There, the CR caused a fatal error (with unhelpful diagnostic).

The solution is to code an exit statement at the end of the PHP. That solves the problem, but I am left asking if anyone knows why it does?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if you have any stray blank lines or echo statements, this will add to the binary stream
mbrampton
Forum Newbie
Posts: 9
Joined: Fri Mar 04, 2005 5:39 pm
Location: North Yorkshire

Post by mbrampton »

No executable statements at all (although a function definition). But there might well have been an odd line after the ?>. That would have been sent then? As a CR?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yep.
mbrampton
Forum Newbie
Posts: 9
Joined: Fri Mar 04, 2005 5:39 pm
Location: North Yorkshire

Post by mbrampton »

Thanks. It's nice to understand what has happened, not just get a fix!
Post Reply