flip115 Posted June 20, 2007 Share Posted June 20, 2007 I'm having trouble finding out how to do this exactly. Basically I have a form (form.html) that visitors fill out: INPUT 1 INPUT 2 INPUT 3 Then when they click Submit they are taken to the results page (form.php) which displays a paragraph with their inputs from the previous form inserted where they need to be: Words words words words words INPUT 1 words words words words INPUT 2 words words words words words INPUT 3. What I need to know is how can I use PHP to have a button on the page where the visitor can click it to open a "Save As" dialog which would save the text in the paragraph (as displayed) to a set file name on their PC? I've experimented a little with having the text written to a file on my server, then the file could be downloaded from a link, but if there are multiple users on at once the file text changes and might not be the same as when the user first submitted the form. Can anyone help me with this? Quote Link to comment Share on other sites More sharing options...
aniesh82 Posted June 20, 2007 Share Posted June 20, 2007 You can do this in many ways: 1. You saved the file to some location on your server. The same method you tried. When creating the filename, add user id also . Suppose 1 is the user id then, file name is 1_filename.php . When user hits the Save As button, you can download the file. You can also create a random file name using the user id and md5, sha1 etc. 2. Another way is by creating the file only when the user clicks the Save As. To do this, OnClick of Save As button, read the contents from javascript and write into a file using Ajax. Then pop up the download now window as earlier. Quote Link to comment Share on other sites More sharing options...
flip115 Posted June 20, 2007 Author Share Posted June 20, 2007 Thanks for the reply. Ok, the file name must always be the same (ie. INFO.DAT) so it cannot be a user specific filename or anything. So would there be a way to simply copy the text and output it to a text file on the users PC only after they select where to save it through the Save As dialog? I'm pretty new to PHP, so I really don't know how to go about writing the script myself. I've tried using a execCommand("SaveAs") command, but this only seems to work in IE, but I would like one that works for all browsers. How does PHP call the SaveAs command, and how can it select a specific area of text and temorarily store it to output to the text file? Thanks, Quote Link to comment Share on other sites More sharing options...
flip115 Posted June 20, 2007 Author Share Posted June 20, 2007 thorpe, I don't see how this is client side. It's for a page that runs on my server. I simply don't know how to make a button where the user viewing the page can click which calls the Save command to save the text file to their PC. I'm trying NOT to use Javascript, but rather PHP if it's possible. Quote Link to comment Share on other sites More sharing options...
myphpcode Posted June 27, 2007 Share Posted June 27, 2007 Hello Why are you worrying about saving that input text, rather you can do one thing, whatever the visitor inputs on form.html. just echo those inputs on form.php file rather than showing it into paragraph. After that use ob_start() and ob_get_contents() function to capture that part of the text and mail those content to user thats all. I hope it will help you. Think Different :-\ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.