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