/    Sign up×
Community /Pin to ProfileBookmark

Finding the path of a directory

Hi I have to get the path of a directory so that I can set up a scheduled task. Ive done multiple searches on this and the following does not work.

[code=php]str_replace(basename($_SERVER[‘PHP_SELF’]), ”, $_SERVER[‘PHP_SELF’]); [/code]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@ChazzlMay 21.2008 — Try this... you might need to switch the slash marks around depending on your server platform (Windows, Linux).
[code=php]<?php
function getFileDirectory(){
$aryPath = explode('\', __FILE__);
array_pop($aryPath);
return implode('\', $aryPath);
}
?>[/code]


OR

[code=php]<?php
function getFileDirectory(){
$aryPath = explode('\', $_SERVER['PHP_SELF']);
array_pop($aryPath);
return implode('\', $aryPath);
}
?>[/code]
Copy linkTweet thisAlerts:
@cs3mwauthorMay 21.2008 — Unfortunately that doesnt work. What Im after is the long directory i.e. somethin similar to usr/bin/ etc
Copy linkTweet thisAlerts:
@ChazzlMay 21.2008 — Check your [i]phpinfo();[/i] for possibilities?
Copy linkTweet thisAlerts:
@cs3mwauthorMay 21.2008 — Yeah thats seems to have the information. Do you kn ow whether it is the

_SERVER["PATH_TRANSLATED"] which I am after? Unfortunately thats not working however knowing my server :mad: it will be the servers fault which is not running scheduled tasks.
Copy linkTweet thisAlerts:
@ChazzlMay 21.2008 — If it has the path you need, that will work. Shouldn't change unless the server changes on occasion.

Test the file path with [i]file_exists()[/i]... if successful then it could be the scheduled task failing?
Copy linkTweet thisAlerts:
@NogDogMay 22.2008 — Is this what you mean?
[code=php]
echo dirname($_SERVER['SCRIPT_FILENAME']);
[/code]
×

Success!

Help @cs3mw 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 6.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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...