Save to file Example
From PlainOldWebserver
HTML form and JavaScript CGI page to go with it to save text to a file that you name.
Savetofile.html
<html> <head> </head> <body> <blockquote> <h4>Save Text To a file:</h4> <hr> <form method='Post' action='savefile.sjs'> <b>File Name:</b><input size="20" name="filename"><br> <b>Data to Save:</b><br/> <TEXTAREA name='filedata' ROWS=20 COLS=60 WRAP></TEXTAREA><br> <INPUT TYPE='SUBMIT' VALUE='Save to File'> </form> </blockquote> </body> </html>
savefile.sjs
<?sjs filename = pow_server.POST['filename']; filename = unescape(filename.replace(/\+/g," ")); filedata = pow_server.POST['filedata']; filedata = unescape(filedata.replace(/\+/g," ")); //Save the form are information to a file named file2.txt pow_file_put_contents(filename, filedata, "w" ); // Build dynamic string using javascript out = "Echo of the Form: <br><table border=2><tr><td> "+ filedata + "</td></tr></table>"; ?> <html> <head> </head> <body> This is the data that was written to <a href="<?sjs document.write(filename); ?>"><b><?sjs document.write(filename); ?></b></a> </BR> <?sjs document.write(out); ?> </body> </html>
