If it\'s Path_To_DocumentRoot/a/b/c.php,should always be /a/b.
I use this:
dirname($_SERVER[\"PHP_SELF\"])
<
PHP < 5.3:
dirname(__FILE__)
PHP >= 5.3:
__DIR__
EDIT:
Here is the code to get path of included file relative to the path of running php file:
$thispath = explode('\\', str_replace('/','\\', dirname(__FILE__)));
$rootpath = explode('\\', str_replace('/','\\', dirname($_SERVER["SCRIPT_FILENAME"])));
$relpath = array();
$dotted = 0;
for ($i = 0; $i < count($rootpath); $i++) {
if ($i >= count($thispath)) {
$dotted++;
}
elseif ($thispath[$i] != $rootpath[$i]) {
$relpath[] = $thispath[$i];
$dotted++;
}
}
print str_repeat('../', $dotted) . implode('/', array_merge($relpath, array_slice($thispath, count($rootpath))));