If it’s Path_To_DocumentRoot/a/b/c.php,should always be /a/b.
I use this:
dirname($_SERVER["PHP_SELF"])
But it won’t work when it’s included by another file in a different directory.
EDIT
I need a relative path to document root .It’s used in web application.
I find there is another question with the same problem,but no accepted answer yet.
Do you have access to
$_SERVER['SCRIPT_NAME']? If you do, doing:Should work. Otherwise do this:
In PHP < 5.3:
Or PHP >= 5.3:
You might need to
realpath()andstr_replace()all\to/to make it fully portable, like this: