note 29468 added to features.commandline
| From: | Alexander at rack1 dot php dot net | Date: | Fri, 14 Feb 2003 11:34:04 +0000 |
| Subject: | note 29468 added to features.commandline | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-43929@lists.php.net to get a copy of this message | ||
How to change current directory in PHP script to script's directory when running it from
command line using PHP 4.3.0?
(you'll probably need to add this to older scripts when running them under PHP 4.3.0 for
backwards compatibility)
Here's what I am using:
chdir(preg_replace('/\\/[^\\/]+$/',"",$PHP_SELF));
Note: documentation says that "PHP_SELF" is not available in command-line PHP scripts.
Though, it IS available. Probably this will be changed in future version, so don't rely on this
line of code...
Use $_SERVER['PHP_SELF'] instead of just $PHP_SELF if you have register_globals=Off
--
http://www.php.net/manual/en/features.commandline.php
http://master.php.net/manage/user-notes.php?action=edit+29468
http://master.php.net/manage/user-notes.php?action=delete+29468
http://master.php.net/manage/user-notes.php?action=reject+29468