$_SERVER['DOCUMENT_ROOT'] would return /home/user/public_html

Now thats fine if your software or script is being using in the main/root directory but what if its being used in a folder or a folder of a folder how do you get that path. Especially when you don't know where a user is going to use it.

something like this;

while ( file_exists ( $fileExtension.'includes/config.php' ) == false )
{
    $fileExtension .= '../';
}

would work alright, but for some things I actually want to use the full path.

So if they had a user had the script in www.example.com/folder/subfolder/demo-script/

The base path would be /home/user/public_html/folder/subfolder/demo-script/

    If you use some sort of application structure where everything is run from one (or more) controller script(s) in the root directory of the application installation, then you could get that installation root via :

    $install_dir = dirname($_SERVER['SCRIPT_FILENAME']);
    

    Or if you have some sort of common config/set-up file used by all the scripts, then you could explicitly define() the installation path there, having the user change it as part of the installation process, either manually or via an installation script.

    So ultimately it will depend to some degree on your application design and your implementation and coding style as to what might work best for you.

      Alright thanks for the help.

        Write a Reply...