Using Headers For Download System

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
Nelsobra
Forum Newbie
Posts: 2
Joined: Thu Jun 16, 2005 3:55 pm

Using Headers For Download System

Post by Nelsobra »

I'm trying to use headers to point the browser to a file download, but I run into the headers already sent error. To rectify this I tried using output buffering, but when I tried this the file would download but would contain an extra 1.6kb of data and would be corrupt(the 1.6kb extra is the size of my style.css file)
To give some background, I have an index.php file which includes my downloads.php file.

Any insight would be appreciated
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

If anything (css,spaced,text) is printed to the browser before the header call. The header() function will throw an error.
Nelsobra
Forum Newbie
Posts: 2
Joined: Thu Jun 16, 2005 3:55 pm

Post by Nelsobra »

I realise that and that's why i've tried to use output buffering, but I still can't manage to get it to work. I believe it might have something to do with the fact that the index file starts output while the downloads.php file is trying to send headers. Whatever the reason is I can't get output buffering to work.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

At first sight your index.php shouldn't "include" but "link to" download.php
Post Reply