Wednesday, May 22, 2024
HomeWeb application programmingPHP programmingPHP: determine the directory path of the server root

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

Quinn McHenry
Quinn McHenry
Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

LATEST REVIEWS

Recent Comments

error: Content is protected !!