Header followed by header

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
User avatar
TonyB
Forum Newbie
Posts: 2
Joined: Thu Aug 06, 2009 7:08 am
Location: Glasgow

Header followed by header

Post by TonyB »

I am trying to download 2 plain text files (help.txt and tender.txt) which are created using PHP’s header command, but when I send the browser the second set of headers, I get a warning saying “headers already sent” (as you would expect) but I need to replace the first set (used by now) with the second set (as they hold my second filename).

I’ve used the replace bit of the header (
header("Content-disposition: attachment; filename=help.txt;", 0);
and
header("Content-disposition: attachment; filename=help.txt;", false);
) and have even tried creating the files using fopen (but that way is ugly).

I’ve scanned the net but did not find anything of use and I’m sure someone has done this before and it really is a piece of cake.
Someone take pity on someone new to PHP and web design and give me an answer to my problem.

Below is my (edited) code at the moment.

Code: Select all

 
 
if (isset($_POST["cb_helpfile"]))
{
     header("Content-disposition: attachment; filename=help.txt;",);
     header("Content-Type:text/plain", 0);
     output_file("help", "HelpIntroduction.txt");   //  function to print out the to the text file
     output_file("help", "HelpControlPanel.txt");
     output_file("help", "HelpOutlook.txt");
}
if (isset($_POST["cb_tender"]))
{
     header("Content-disposition: attachment; filename=tender.txt;");
//  THIS IS WHERE IT GOES WRONG
     header("Content-Type:text/plain");
     output_file("tender", "TenderFrontPage.txt");
     output_file("tender", "TenderIntroduction.txt");
}
 
:banghead:
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Header followed by header

Post by onion2k »

You can only download one file at a time, so if you're trying to download two separate files it's not going to work. If you need to download two compress them into a gzip or a zip file.
User avatar
TonyB
Forum Newbie
Posts: 2
Joined: Thu Aug 06, 2009 7:08 am
Location: Glasgow

Re: Header followed by header

Post by TonyB »

Thanks for that. I thought that was the answer. Nice to have your thoughts confirmed.

Perhaps I'll go back to writing a couple of files (have a permissions issue on the server but I can sort that) or figure out a way of firing off two pages and download one file per page.

Oh well.

:|
Post Reply