You having default PHP functions to get the web server document within the $_SERVER super global array, and for getting the current working directory with the getcwd() function. But it often occurs that the document is being served from another directory within the web tree. This function will get the current working directory, relative to the web server document root.
<?php
function getRelativeRoot()
{
$dr = $_SERVER['DOCUMENT_ROOT'];
$cwd = getcwd();
return str_replace($dr, ”, $cwd);
}
?>
Example:
<?php
$relative_root = getRelativeroot();
echo $relative_root;
?>



Posted in