This commit is contained in:
awesomeuser 2023-08-01 23:42:38 +00:00
parent 389cd1c1cc
commit 3ea23ed190

View file

@ -77,29 +77,28 @@
</div> </div>
<?php <?php
// write to file // read file into string
if (!is_null($_POST["body"]) && strlen($_POST["body"]) != 0) { $myfile = fopen("posts.txt", "r") or die("Unable to open file!");
// read into a string and concatenate new post to the beginning of the string $content = fread($myfile,filesize("posts.txt"));
$myfile = fopen("posts.txt", "r") or die("Unable to open file!"); fclose($myfile);
$construct = fread($myfile,filesize("posts.txt"));
fclose($myfile);
// write new post to file if necessary
if (!is_null($_POST["body"]) && strlen($_POST["body"]) != 0) {
// concatenate new post to the beginning of the string
$signature = "anonymous"; $signature = "anonymous";
if (!is_null($_POST["signature"]) && strlen($_POST["signature"]) != 0) { if (!is_null($_POST["signature"]) && strlen($_POST["signature"]) != 0) {
$signature = htmlspecialchars($_POST["signature"]); $signature = htmlspecialchars($_POST["signature"]);
} }
$construct = $signature . " [UTC " . date("m/d/Y H:i") . "] " . htmlspecialchars($_POST["body"]) . "<br>" . $construct; $content = $signature . " [UTC " . date("m/d/Y H:i") . "] " . htmlspecialchars($_POST["body"]) . "<br>" . $construct;
// write back into the file // write string back into the file
$myfile = fopen("posts.txt", "w") or die("Unable to open file!"); $myfile = fopen("posts.txt", "w") or die("Unable to open file!");
fwrite($myfile, $construct); fwrite($myfile, $content);
fclose($myfile); fclose($myfile);
} }
// read from file // show content
$myfile = fopen("posts.txt", "r") or die("Unable to open file!"); echo $content;
echo fread($myfile,filesize("posts.txt"));
fclose($myfile);
?> ?>
</body> </body>