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
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
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.
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'];