just assemble content in file

This commit is contained in:
awesomeuser 2023-08-01 23:52:48 +00:00
parent 4f875a2561
commit 5e83262034

View file

@ -70,44 +70,32 @@
</div>
<div class="post">
<h2>anon</h2>
<i>mm/dd/yyyy</i>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dignissim sapien ut ornare elementum. Nullam vel accumsan quam. Nam vitae nibh nibh. Sed ultrices vulputate odio in volutpat. Nullam elementum tellus vel purus aliquam egestas. Cras congue diam sit amet sapien faucibus ultricies. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus sit amet arcu vitae nulla tempus blandit ac quis nibh. Mauris vel metus vel lorem venenatis facilisis mattis vel dui. Ut est purus, ultricies blandit justo tempor, porttitor porttitor erat. Praesent non felis ultricies, scelerisque dui nec, egestas lectus. Suspendisse euismod ultricies pharetra. Aenean aliquam mauris sit amet arcu scelerisque, a sollicitudin ipsum laoreet. Praesent a venenatis velit, nec fringilla mi. Nunc dignissim tortor vel odio pulvinar, vitae euismod diam tincidunt. In ullamcorper urna nec ex dapibus luctus.</div>
</div>
<?php
$size = filesize("posts.txt");
// write new post to file if necessary
if (!is_null($_POST["body"]) && strlen($_POST["body"]) != 0) {
// read file into string
$myfile = fopen("posts.txt", "r") or die("Unable to open file!");
$content = 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";
if (!is_null($_POST["signature"]) && strlen($_POST["signature"]) != 0) {
$signature = htmlspecialchars($_POST["signature"]);
}
$content = $signature . "<br>UTC " . date("m/d/Y H:i") . "<br>" . htmlspecialchars($_POST["body"]) . "<br>" . $content;
$content = "<div class='post'><h2>" . $signature . "</h2><i>UTC" . date("m/d/Y H:i") . "</i><div>" . htmlspecialchars($_POST["body"]) . "</div>" . $content;
// write string back into the file
$myfile = fopen("posts.txt", "w") or die("Unable to open file!");
fwrite($myfile, $content);
fclose($myfile);
// update size with new change
$size = strlen($content);
}
// read and show content
$myfile = fopen("posts.txt", "r") or die("Unable to open file!");
while(!feof($myfile)) {
echo fgets($myfile) . "<br>";
}
fclose($myfile);
// show content
echo $content;
?>
</body>