Header followed by header
Posted: Thu Aug 06, 2009 7:16 am
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.

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");
}