I am using the PHP include statement to enable publication of a piece of news. The news is filed as "news.txt" and the user has access to a directory to upload the file or delete old news but no access to the code.

If the file does not exist there will be a cryptic error message. What I want to do is enable another include which will load another txt file with the message for example: "Awaiting news" if "news.txt" is removed, because its old news.


OK, so go for it. Maybe you'll want to go to the documentation and look up "file_exists".


I found this: bool file_exists ( string $filename )
So the first problem is what is $filename. do I just change it to $news.txt. If so do I need to also add the path?

Perhaps Googling file_exists will give you a few examples? Anyway, this is the first example from the page you supposedly read:

$filename = '/path/to/foo.txt';

if (file_exists($filename)) {
    echo "The file $filename exists";
} else {
    echo "The file $filename does not exist";

Apologies to php.net for the reproduction.
Doesn't that answer your question?
What is it you don't understand specifically?

This question has already been answered. Start a new discussion instead.