2009/06/25

include library files

If you hosted your site somewhere, your probably wanted to know where the root directory path is, in order to include (or require) some library files, which requires a whole path.

If you hosted on linux system, then it is easy to find it out, by

$docRoot = getenv("DOCUMENT_ROOT");
include ($docRoot . "path/to/yourfile");

However, if you hosted on IIS system, then getenv would not work. Here is a workaround:

require_once(dirname(__FILE__) . '/../includes/utils.php');
require_once(dirname(__FILE__) . '/includes/utils.php');
Note: direname(__FILE__)return the current dir name, so you need to tweak it a bit (for example, ‘..’ means jump up a level) to find out a correct library files.

No comments:

Post a Comment