File Contents:
das das dasdsad fggds
das das dasdsad fggds
<?php
include('includes/header.php');
$file = 'data.txt';
// 1. WRITE to the file when the form is submitted
if (isset($_POST['text']) && $_POST['text'] !== '') {
$line = $_POST['text'] . "\n";
file_put_contents($file, $line, FILE_APPEND);
}
// 2. READ the file contents (if it exists)
$contents = file_exists($file) ? file_get_contents($file) : 'File is empty.';
?>
<form method="post">
<input type="text" name="text" placeholder="Type something..." required>
<button type="submit">Save to File</button>
</form>
<h3>File Contents:</h3>
<pre><?php echo htmlspecialchars($contents); ?></pre>
<?php include('includes/footer.php'); ?>