PHP: determine the directory path of the server root

Home -> Programming -> Web -> PHP

24110 views

From the computer of: qmchenry (338 recipes)
Created: Jan 04, 2004


Add a comment

Add to:
Add to stumbleuponAdd to del.icio.usDigg itAdd to FURL

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

Subscribe to the Tech-Recipes Newsletter

You can get tips like this delivered in your email every week!

Enter your Email

We will never, ever sell your email address or spam you.





Related recipes:

  PHP: Delete or unlink a file on the server
  PHP conditional syntax: less than
  PHP conditional syntax: greater than
  PHP if statement syntax
  PHP: Rename or move a file on the server
  PHP conditional syntax: inequality
  PHP: Set or create a simple browser cookie with setcookie
  Solve PHP Fatal error: Allowed memory size of 8388608 bytes exhausted (tried...
  PHP: Upload Files to the server
  PHP: Break apart strings with explode

 

Sponsored links

 

Login

Nickname

Password

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.