yup
This commit is contained in:
parent
389cd1c1cc
commit
3ea23ed190
1 changed files with 12 additions and 13 deletions
21
index.php
21
index.php
|
@ -77,29 +77,28 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
// write to file
|
// read file into string
|
||||||
if (!is_null($_POST["body"]) && strlen($_POST["body"]) != 0) {
|
|
||||||
// read into a string and concatenate new post to the beginning of the string
|
|
||||||
$myfile = fopen("posts.txt", "r") or die("Unable to open file!");
|
$myfile = fopen("posts.txt", "r") or die("Unable to open file!");
|
||||||
$construct = fread($myfile,filesize("posts.txt"));
|
$content = fread($myfile,filesize("posts.txt"));
|
||||||
fclose($myfile);
|
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>
|
||||||
|
|
Reference in a new issue