ahs10 Posted February 11, 2008 Share Posted February 11, 2008 so i have a popup window which is a php script that makes a an excel spreadsheet that automatically downloads to the user's computer. the last lines of that script are... header("Content-Type: application/vnd.ms-excel; name=\"" . $fileName . ".xls\""); header("Content-Diposition: inline; filename=\"" . $fileName . ".xls\""); $fh=fopen($fname, "rb"); fpassthru($fh); unlink($fname); now, i've always had a little trouble grasping headers, and placing other content on the page. my goal here is to 1 - get a little insight on how headers work (i know where the PHP manual is too... it's not the best written site in the world), and 2 - figure out how to execute javascript after this code completes to close the window. i keep getting the "headers already defined...." bit. any help is much appreciated. thanks! Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted February 11, 2008 Share Posted February 11, 2008 You always need to send headers before any content is output. The reason for your error is that the headers are sent after something has been outputted. If you wish to execute Javascript after the page has loaded then you'll have to set an event handler to <body>'s onload or set a timer. If you wish to learn more about the headers then you should look into the HTTP protocol. The PHP manual is quite fine and in my opinion excellent, but it's supposed to cover PHP, not HTTP so that's why it doesn't talk very much about headers. Here are some of the headers: http://en.wikipedia.org/wiki/List_of_HTTP_headers. The headers on that list you would be sending using PHP would be the response headers. Quote Link to comment Share on other sites More sharing options...
ahs10 Posted February 11, 2008 Author Share Posted February 11, 2008 i will will check out that link, thanks for that explanation too, very helpful. however, even trying to echo a simple text string after that code does not work. for example if i put.... echo "testing"; after the code i wrote above. that's output after a header... err wait, maybe i should check out that link now. it would make sense that if i defined a header as excel content, that "testing" would appear in the excel spreadsheet... or maybe not, but it wouldn't know to display it in the web browser.... hmmm, ok now i'm thinking aloud and rambling..... anyweezer, thanks again! Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted February 11, 2008 Share Posted February 11, 2008 Yes, the "testing" would appear as part of the spreadsheet, so it would probably just break it. It would be the correct place (after) to position the string though. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.