Relative root path in PHP
PHP has Magic Constants, like __DIR__ and __FILE__. But (unfortunately?) those will point to the directory and the file where the constants are referenced; e.g., index.php will show /path/to/index.php, while a class contained in a file in a lib/ directory will have /path/to/lib/ClassFile.php. For webserver executed scripts, a good way of getting the "relative root" is via:
$_SERVER["SCRIPT_FILENAME"]
Like so:
$db_class_dir = dirname( $_SERVER["SCRIPT_FILENAME"] ) . DIRECTORY_SEPARATOR;
Comments
Post a Comment