RabbieBurns Posted October 15, 2009 Posted October 15, 2009 Im after a really simple php page, that will simply have a single text box, and a submit button, and basically just take the contents of the text box and append it to a file on the server... Anyone able to knock something up for me please?
gibbo_ap Posted October 15, 2009 Posted October 15, 2009 what to you want it to save it to a text file or a db?
RabbieBurns Posted October 15, 2009 Author Posted October 15, 2009 just a plaintext file, each entry on a new line..
PEO Posted October 15, 2009 Posted October 15, 2009 Im after a really simple php page, that will simply have a single text box, and a submit button, and basically just take the contents of the text box and append it to a file on the server... Anyone able to knock something up for me please? I have exactly what you need but its asp and runs on ISA any good for you? 1
PEO Posted October 15, 2009 Posted October 15, 2009 except mine is save to an excel file, but each new entry is saved to a new line 1
PEO Posted October 15, 2009 Posted October 15, 2009 Ok I've modified it so it produces a txt file for you. Intrested? 1
RabbieBurns Posted October 15, 2009 Author Posted October 15, 2009 asp would be alright if i could get asp working on apache.. also it needs to be plaintext on one line only as another script on the server is going to be reading the text file
RabbieBurns Posted October 15, 2009 Author Posted October 15, 2009 Just seen your post. Yeh I guess ASP would be alright, Ill just run it on one of my windows VMs.. Cheers!
PEO Posted October 15, 2009 Posted October 15, 2009 here you go this should do for you, it will create a text file called results soon as you submit the formweb.zip 1
webman Posted October 15, 2009 Posted October 15, 2009 Thanks for remind me why I hate ASP In PHP... if(isset($_POST['content'])){ $filename = 'foo.txt'; $fhandle = fopen($filename, 'a'); fwrite($fhandle, $_POST['content'] . "\n"); fclose($fhandle); echo 'File has probaly been written.'; } else { ?> </pre><form method="post"> </form><br><br>}<br 1
RabbieBurns Posted October 15, 2009 Author Posted October 15, 2009 Works almost, it appends ,Submit to the end of each line though..
RabbieBurns Posted October 15, 2009 Author Posted October 15, 2009 that last post was for PEO.. Cheers webman, ill give that a go now
dhicks Posted October 15, 2009 Posted October 15, 2009 Im after a really simple php page, that will simply have a single text box, and a submit button, and basically just take the contents of the text box and append it to a file on the server. Will more than one person be using it at a time? Like a class of 30 children? If so, watch out for race conditions when writing files - one user gets a handle on a file, then another user, they both think they are writing to the same point in the file and one users' data gets lost. This is why most modern web development is done with databases, as they ensure sequential writing of data. -- David Hicks 1
RabbieBurns Posted October 15, 2009 Author Posted October 15, 2009 webman, that works a treat.. thanks heaps
RabbieBurns Posted October 15, 2009 Author Posted October 15, 2009 Will more than one person be using it at a time? Like a class of 30 children? If so, watch out for race conditions when writing files - one user gets a handle on a file, then another user, they both think they are writing to the same point in the file and one users' data gets lost. This is why most modern web development is done with databases, as they ensure sequential writing of data. -- David Hicks I missed this post completely sorry. Its only going to be a rarely used thing, and Ill be the only one using it.. thanks for the info though
RabbieBurns Posted October 15, 2009 Author Posted October 15, 2009 webman, do you happen to have a mail function that I could add to that that would email using a smtp the string that was entered to a certain email address?
webman Posted October 15, 2009 Posted October 15, 2009 Yep. This should work; but it depends largely on the server's configuration and if it has a mail transport agent installed (MTA). $to = '[email protected]'; $subject = 'Web Form'; $body = "File appended with data:\n\n {$_POST['content']}"; $headers = 'From: Web Form '; mail($to, $subject, $body, $headers); ?> 1
RabbieBurns Posted October 22, 2009 Author Posted October 22, 2009 I cant get the mail bit working but i think thats my sendmail not working more than anything... Ive got it as this so far, but im looking to add one more function.. (I added in a bit to show what was in the file already.. probably crude/bad but it works heh) if(isset($_POST['content'])){ $filename = 'file.txt'; $fhandle = fopen($filename, 'a'); fwrite($fhandle, $_POST['content'] . "\n"); fclose($fhandle); echo 'Added to file.'; } else { ?> One Line Submission Currently in file: $file = "file.txt"; $f = fopen($file, "r"); while ( $line = fgets($f, 1000) ) { print $line. " "; } ?> Enter your line </pre><form method="post"> </form><br><br><br>}<br>?&g What I would like to do, and I dont know if its possible, but after it writes the 'Added to file' text, to have a button, which when pressed would execute a script to run on the server... Is that even possible?
webman Posted October 22, 2009 Posted October 22, 2009 What I would like to do, and I dont know if its possible, but after it writes the 'Added to file' text, to have a button, which when pressed would execute a script to run on the server... Is that even possible? Do you mean to just re-direct the browser to a separate page? Or do something without the user noticing?
RabbieBurns Posted October 22, 2009 Author Posted October 22, 2009 Do you mean to just re-direct the browser to a separate page? Or do something without the user noticing? I want it to display a link/button, which when clicked, executes a script on the server. Is there a function for this in php? At the moment I have put the script into the servers cgi-bin folder, but when I click on it it just tries to send me the script as a download.. Its a python script if that makes any difference from what im trying to do.. edit: Ive just found this in google, is this what Im after? shell_exec("python myscript.py");
webman Posted October 22, 2009 Posted October 22, 2009 Yes, if the web server is not configured to run Python scripts, then it will just offer it as a download. The shell_exec() would probably work, yes. But there are different methods for running external processes - it would be worth finding out which one is best for your needs. There's passthru(), exec() and system() available at your disposal. PHP: Program execution - Manual
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now