Return to Snippet

Revision: 23109
at January 30, 2010 11:28 by arthipesa


Initial Code
function resolveDocumentRoot() {
    $current_script = dirname($_SERVER['SCRIPT_NAME']);
    $current_path   = dirname($_SERVER['SCRIPT_FILENAME']);
   
    /* work out how many folders we are away from document_root
       by working out how many folders deep we are from the url.
       this isn't fool proof */
    $adjust = explode("/", $current_script);
    $adjust = count($adjust)-1;
   
    /* move up the path with ../ */
    $traverse = str_repeat("../", $adjust);
    $adjusted_path = sprintf("%s/%s", $current_path, $traverse);

    /* real path expands the ../'s to the correct folder names */
    return realpath($adjusted_path);   
}

Initial URL
http://code.arthipesa.com/

Initial Description


Initial Title
Resolving Current Document Root

Initial Tags


Initial Language
PHP