just assemble content in file
This commit is contained in:
parent
4f875a2561
commit
5e83262034
1 changed files with 8 additions and 20 deletions
28
index.php
28
index.php
|
@ -70,44 +70,32 @@
|
||||||
|
|
||||||
</div>
|
</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>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>
|
</div>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
$size = filesize("posts.txt");
|
// 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
|
// write new post to file if necessary
|
||||||
if (!is_null($_POST["body"]) && strlen($_POST["body"]) != 0) {
|
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);
|
|
||||||
|
|
||||||
// concatenate new post to the beginning of the string
|
// 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"]);
|
||||||
}
|
}
|
||||||
$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
|
// 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, $content);
|
fwrite($myfile, $content);
|
||||||
fclose($myfile);
|
fclose($myfile);
|
||||||
|
|
||||||
// update size with new change
|
|
||||||
$size = strlen($content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// read and show content
|
// show content
|
||||||
$myfile = fopen("posts.txt", "r") or die("Unable to open file!");
|
echo $content;
|
||||||
while(!feof($myfile)) {
|
|
||||||
echo fgets($myfile) . "<br>";
|
|
||||||
}
|
|
||||||
fclose($myfile);
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
Reference in a new issue