PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Ayashi
Forum Newbie
Posts: 2 Joined: Wed Jan 30, 2008 4:17 am
Post
by Ayashi » Wed Jan 30, 2008 4:21 am
hi all,
I'm trying to figure out the base path of a script called by a cron job :
Code: Select all
Zharma scripts # crontab -l
* * * * * /usr/bin/php /home/webroot/scripts/crontab.php >> /home/webroot/scripts/crontab.log
Looking in $_SERVER["PWD"] give me a wrong value. ( /root )
is there a way to figure out the real folder ( /home/webroot/scripts/ )
Kind regards,
Aya.
Ayashi
Forum Newbie
Posts: 2 Joined: Wed Jan 30, 2008 4:17 am
Post
by Ayashi » Wed Jan 30, 2008 4:58 am
Found a trick :
Code: Select all
$FileName = $_SERVER["PATH_TRANSLATED"];
$Values = split("/",$FileName);
for ($i=0;$i<=count($Values)-2;$i++)
$Path = $Path.$Values[$i]."/";
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Jan 30, 2008 9:57 am
Untested, but try this:
Code: Select all
$real_path = realpath($_SERVER['SCRIPT_FILENAME']);
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
rsmarsha
Forum Contributor
Posts: 242 Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England
Post
by rsmarsha » Wed Jan 30, 2008 10:34 am
If you make a file as below:
And place it in the same folder as the script you want the path for, you'll be able to see the absolute paths and other info.