1.11M Members

php include selected file or another

 
0
 

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

 
0
 

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

 
0
 

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?

 
1
 

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?

Question Answered as of 2 Years Ago by diafol and chrishea
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: