On Mon, Nov 12, 2001 at 11:14:04AM +0530, Sharat Hegde wrote: > Hello, > > I need to capture the contents of a Form into a text file format and > automatically allow the user to Save the file to his desktop. > > Here is what I am intending to do: > * Capture the form contents and save to a temporary file. This works fine. > * Provide some method of the user automatically downloading this. How do I > get this download to happen? > > I want the screen which says "Open File or Save" to come up and then the > user can basically save to his desktop.
It's not even necessary to save the form data to a file on the server if you're just going to remove it after the user downloads the text file. The key to this is knowing the proper HTTP headers to send, to inform the browser that it should download a file. Then simply print the desired form data to stdout, and it'll be fed into the file that the user saves. For example: <? if ($action == 'Get Text File') { // Tell the browser to display a 'save file' dialog Header('Content-Type: application/octet-stream'); Header('Content-Disposition: attachment; filename="formdata.txt"'); // Print the text to be sent as formdata.txt echo "First text field: $firstfield\n"; echo "Second text field: $secondfield\n"; exit; } ?> <form method="post" action="<?= $PHP_SELF ?>"> First: <input type="text" name="firstfield"><br> Seond: <input type="text" name="secondfield"><br> <input type="submit" name="action" value="Get Text File"> </form> Here, the form takes in two text strings, and offers them to the browser as a file. Matt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]