PHP: determine the directory path of the server root

Contributor Icon Contributed by qmchenry Date Icon January 4, 2004  
Tag Icon Tagged: PHP programming

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

Previous recipe | Next recipe |
 
  • Prathiban
    I guess It is
    $_SERVER['DOCUMENT_ROOT'];
  • George
    this does not work in my php 5 installation.
  • This doesnt work if you running your site from an alias or virtual directory
  • independentbrit
    Doesn't work for me. I wonder if it is a super global and these are turned off.
  • e
    echo(realpath(__FILE__));
blog comments powered by Disqus