if statement for checking if posts file exists

This commit is contained in:
awesomeuser 2023-08-02 22:13:50 +00:00
parent f50b2817e3
commit a492989894

View file

@ -109,8 +109,10 @@
<?php <?php
// ensure the file exists before attempting to read from it // ensure the file exists before attempting to read from it
$myfile = fopen("posts.txt", "a"); if (!file_exists("posts.txt")) {
fclose($myfile); $myfile = fopen("posts.txt", "a");
fclose($myfile);
}
// show content // show content
$myfile = fopen("posts.txt", "r") or die("Unable to open file!"); $myfile = fopen("posts.txt", "r") or die("Unable to open file!");