If you have a shell account access, then you can use pwd (if it's a unix based
server), this can be executed from a php script too.
<?PHP echo exec('pwd'); ?>
If you try to use
<?PHP echo $_SERVER['DOCUMENT_ROOT']; ?>
you will only get the path to the main server that is defined in the server
settings, so it's quite useless in most cases.
In this case you get a better result from
<?PHP echo $_SERVER['PHP_SELF'']; ?>
but you can get a path like /~username/html/myscript.php
instead of /home/username/html/myscript.php
<?PHP echo $_SERVER['PATH_TRANSLATED']; ?>
May work, shouldn't work with Apache2, and gives you the full path to the
script (~ is translated to a path).