This article mainly introduces the PHP access to the site root directory of the physical path of several methods, has a certain reference value, now share to everyone, the need for friends can refer to
Gets the physical path of the Web site root directory in PHP.
In the development of PHP program often need to get the current site directory, we can use the constant definition to obtain the site root directory physical path, convenient for the application.
Here are a few common ways to get the root directory of your Web site.
PHP get web site root method one:
<?phpdefine ("WWWROOT", Str_ireplace (Str_replace ("/", "\ \", $_server[' php_self ']), ", __file__)." \ "); Echo WWWROOT;? >
PHP get web site root method two:
<?phpdefine (' Www_path ', str_replace (' \ \ ', '/', Realpath (dirname). ' /.. /'))); Define the Site Directory?>
PHP get web site root method three:
$_server[' document_root '///the document root directory where the script is currently running. Defined in the server configuration file.