Hi

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.

Geoff

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

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

Thanks,

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?

Member Avatar for diafol

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

<?php
$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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.