tags:

views:

138

answers:

4

how can i save some variables in a txt file for the user? dont want to generate and store in my server, just want to generate and then the user save on his pc, nothing changes on the server

btw, is this operation heavy on resources?

thanks

A: 
header('Content-Type: text/plain');
echo "Text stuff! Cool!";

(For some reason, SO stripped my opening php-tag.)

gnud
ok he anwsered, but thanks again
+5  A: 

You can do that like this:

header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename=downloadedfile.txt');
echo "Text stuff! Cool!";

If the user loads this page, a Save As-window comes up, asking where to save "downloadedfile.txt", which will have the content "Text stuff! Cool!"

Douwe Maan
+4  A: 

You can hint to the browser that your response is a file which should be saved by using a Content-Disposition header:

header('Content-Disposition: attachment; filename="filename.txt"');
header('Content-Type: text/plain');
echo "Desired file contents";

Note that this does imply you are generating the file on the server, which your question suggests isn't what you want. You could build up the file contents in Javascript on the client side, then create a link using the data uri scheme to allow download. However, it's not support by all browsers, you can't force a "save as", and there are some size limits on what you can generate.

Paul Dixon
A: 

I am not sure I understand your question correctly, but if you want to store information on the client side and retrieve it again later when the user returns you could handle state using:

tosh
no retrieve, hehe