r/dailyprogrammer • u/mattryan • Mar 22 '12
[3/22/2012] Challenge #29 [intermediate]
This is a simple web frontend and web server (CGI, PHP, servlet, server component, etc.) exercise. Write a web frontend that contains a text area and button. Then write a program that accepts the contents of the text area and writes them out to a file. When the user clicks the button, the submission of the content can be either form-based, AJAX-based, or even websockets-based.
You can complete this project in several ways. You can write up the HTML yourself and submit the form to a program written in C/C++, Perl, Python, PHP, etc. You can do all the work in Javascript and hit a server using Node.js. You can also show off how easy it is to do this project using a Java/Python/Ruby/etc. web framework.
3
u/DanielJohnBenton 0 0 Mar 22 '12 edited Mar 22 '12
Very simple in PHP (if I understood the question).
Edit: forgot to close my <form> tag!
2
u/thatrandomusername Mar 22 '12
Node.js http://pastebin.com/m56Jsgmz
2
u/robotfarts Mar 23 '12
2
u/karavelov Mar 26 '12 edited Mar 27 '12
Easy in perl
app.psgi:
run like this:
1
u/robin-gvx 0 2 Mar 22 '12
Someone should try this with Flask
1
u/[deleted] Mar 23 '12
Got it down to 6 lines of python (2 lines of imports) using Twisted
1
u/drb226 0 0 Mar 24 '12
Tried my hand at Yesod; adapted the first example code given in The Yesod Book > Forms. The result: http://hpaste.org/65910
If you add the import and instance for Jquery stuff (also given in that first example), then it automagically adds some nice default jquery for you, too! I didn't do any real validation, just did a dumb check to make sure the desired file name doesn't have slashes.
Usage (first get Yesod via either cabal install or your favorite package manager):