/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] file_exists

Look, I’m having a problem using the file_exists() function.
I have this include.php file which many pages are including [/index.php, /admin/index.php, etx] But inside this include.php file I have to check if a file exists.. The thing is that I don’t know from which file include.php is being included.. So if I would have this:

include.php (in root directory)

[code=php]
if (file_exists(“install.php”)) {
echo “It exists”;
} else {
echo “It does not exist!”;
}
[/code]

index.php (in root directory and install.php exists in the same directory)

[code=php]
include(“include.php”); //Will echo “It exists”
[/code]

/admin/index.php (in /admin/ directory and no install.php exists in the same directory)

[code=php]
include(“../include.php”); //Will echo “It does not exist!”
[/code]

As you see, the function file_exists() does not began lookin in the directory in which the script that is calling it is located; but in the directory where the main script (the one that does the include) is located..
What can I do to make the function began lookin in the directory where include.php is? Thanks!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 28.2006 — [code=php]
$installFilePath = dirname(__FILE__) . '/install.php';
if(file_exists($installFilePath))
{
[/code]
Copy linkTweet thisAlerts:
@delr2691authorNov 29.2006 — nice.. ? thanks a lot!
×

Success!

Help @delr2691 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...