We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,478 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

php include selected file or another

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

3
Contributors
3
Replies
55 Minutes
Discussion Span
2 Years Ago
Last Updated
4
Views
Question
Answered
ggeoff
Posting Whiz in Training
215 posts since Aug 2007
Reputation Points: 14
Solved Threads: 0
Skill Endorsements: 0

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

chrishea
Nearly a Posting Virtuoso
1,485 posts since Sep 2008
Reputation Points: 223
Solved Threads: 243
Skill Endorsements: 5

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?

ggeoff
Posting Whiz in Training
215 posts since Aug 2007
Reputation Points: 14
Solved Threads: 0
Skill Endorsements: 0

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?

diafol
Keep Smiling
Moderator
10,675 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
Question Answered as of 1 Year Ago by chrishea and diafol

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0817 seconds using 2.73MB