This is my HTML on index.html
<form name="userinput" action="usersave.php" method="post">
Your name: <input type="text" name="username><br>
Your email: <input type="text" name="useremail"><br>
Your story: <textarea rows="3" cols="50" name="userstory"></textarea><br>
<input type="submit" value="Submit!" name="submit">
</form>
And this is my PHP on usersave.php
<header>
<?php
$file = 'output.txt';
$buffer = $_POST['userstory'];
if (file_exists($file)) {
$buffer = file_get_contents($file) . "\n" . $buffer;
}
$success = file_put_contents($file, $buffer);
?>
</header>
Delete before khi write thêm
unlink($file);
====
Code 2
<?php
$file_path = "text_file.txt";
$file_handle = fopen($file_path, 'r'); // OPEN FILE READY FOR 'R'eading!
$text_data = fread($file_handle, filesize($file_path)); //Read actual data in file
print $text_data; // print the data you can use echo if you like
fclose($file_handle); // Close the file read / buffer
$data_to_write = "This is the data that will be written to disk!";
$file_path = "new_file.txt";
$file_handle = fopen($file_path, 'w'); // OPEN FILE READY FOR 'W'riting!
fwrite($file_handle, $data_to_write);
fclose($file_handle);
?>