PHP: determine the directory path of the server root
It is sometimes necessary to refer to files in the host filesystem explicitly. By retrieving this information dynamically instead of hard coding it, moving the code from one server or hosting company to another is much simpler.
The fully qualified path of the directory containing the root of the web documents is:
$_SERVER["SITE_HTMLROOT"]
To assign the fully qualified path of images/sadie.gif to the variable $pic:
$var = $_SERVER["SITE_HTMLROOT"].'/images/sadie.gif';











Prathiban said on October 9, 2008
I guess It is
$_SERVER['DOCUMENT_ROOT'];
George said on December 4, 2008
this does not work in my php 5 installation.
Dave said on August 11, 2009
This doesnt work if you running your site from an alias or virtual directory
Anonymous said on September 23, 2009
Doesn’t work for me. I wonder if it is a super global and these are turned off.
e said on November 4, 2009
echo(realpath(__FILE__));
Anonymous said on April 29, 2010
It’s Working Thanx Dude for sharing
Jb said on January 26, 2011
definitely appreciated
Final said on April 25, 2011
Thx man :)