PDA

View Full Version : Allowing a user to save a text file which is created dynamically?


Darksbane
10-11-2002, 01:40 AM
OK, I have a webpage which has lots of different options a user can select. I would like to let my users save just the options they selected as a text file on their personal computer.

So for example a user chooses options A, B, C, and D and then they press some kind of button on the page and a "Save As" dialog pops up asking what they want to save their selections as. This creates a text file with a name of their choosing on their hard drive that says "You selected options A, B, C, and D"

Is this possible? And if so could someone please explain to me how it can be done.

Thanks,
Darksbane

Dylan Leblanc
10-11-2002, 10:11 AM
You can probably use the header() function to do this.

The user selects their options, submits the form, which sends them to a PHP page. In that page the header() function is called with the correct paramater to tell their browser the file should be downloaded and saved rather then displayed. The page also contains some text in the format you described.

The header() function is used to set lines in the HTTP header a webpage. Look it up in a function reference. Here is a page with acceptable HTTP header lines: http://www.cs.tut.fi/~jkorpela/http.html

I do not know which one will tell the browser the file should be saved though.

Dylan Leblanc
10-11-2002, 10:13 AM
here you go

Content-disposition: attachment; filename=fname.ext

http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q260519&