Gutanoth
Gutanoth

Reputation: 842

edit a textfile that is stored on the server

I know this is not best practise.. But I am forced to finish this task in 8 hours and was given this "half-finished" project because the original engineer was let go.

Totally rewriting the project would take too long, priority now, is that it works.

I have a Beaglebone Black board on wich I have a webserver running. On this server I have a txtfile with a string.

on this server, is a website with some buttons. The only thing that needs to be done is:

User clicks on button "a" and an "a" gets added to the txtfile.

No more no less. But due to my lack of knowledge about html and javascript, I came here.

Upvotes: 0

Views: 60

Answers (2)

douweegbertje
douweegbertje

Reputation: 86

If it gets added to a current txt file:

$textFromTheButton = 'A';
$f = fopen( 'yourfile.txt', 'a' );
fwrite( $f, $textFromTheButton );
fclose( $f );

Now you will have to find a way to get the data. You can use a $_POST or $_GET. Just be carefull when using $_GET, since the data is easy altered. Even with a $_POST you must be sure to check your data before writing it to your file. Never trust user input.

Upvotes: 1

Cracker0dks
Cracker0dks

Reputation: 2490

  1. Make a html Form

    < form method="GET" action="yourPhpFile.php"> < button name="data" value="a">A< /button> < /form>

  2. Handle request in backround (php or .net or something)

PHP would be like:

if(isset($_GET["data"])) {
   $getV =  $_GET["data"]; //If you have get
   $file = 'newDataValues.txt';
   file_put_contents($file, $getV);
}

thats it!

Upvotes: 1

Related Questions