Jump to content

header question


ahs10

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.