Get directory from the server

2

How can I get the directory where the server is located using PHP?

The directory of the server and not the file where the script will be run

    
asked by anonymous 09.03.2015 / 15:46

2 answers

6

I think this is what you want:

echo realpath(dirname(__FILE__));

See working on ideone .

Documentation dirname() and realpath() and __FILE__ .

__FILE__ gives the file path, dirname() takes only the directory by ignoring the file name (can be done with any path since what it takes is the parent directory of the path and the realpath() takes the absolute path of the relative address found. You can use a combination of them as needed.

    
09.03.2015 / 15:54
5

This information can be obtained through the array $_SERVER passing as argument DOCUMENT_ROOT .

  

DOCUMENT_ROOT : The root directory under which the current script is run,   as defined in the server configuration files.

echo $_SERVER['DOCUMENT_ROOT'];
    
09.03.2015 / 16:03