Hi Matt, Thanks. That was very useful and it worked like a gem!
Three cheers to HTTP headers. Where do you get a simplified version of the HTTP Header documentation - The W3C specs do not look like interesting reading. Regards, Sharat Hegde Phone: 6560360 Ext 4680 -----Original Message----- From: Matt McClanahan [mailto:[EMAIL PROTECTED]] Sent: Monday, November 12, 2001 2:25 PM To: Sharat Hegde Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Save to Desktop 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 ********************************************************************* Disclaimer: The information in this e-mail and any attachments is confidential / privileged. It is intended solely for the addressee or addressees. If you are not the addressee indicated in this message, you may not copy or deliver this message to anyone. In such case, you should destroy this message and kindly notify the sender by reply email. Please advise immediately if you or your employer does not consent to Internet email for messages of this kind. ********************************************************************* -- 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]