Hello,
say i have a file /var/www/foo/test.php
how do i find out it's path from within it. i'm trying to create an "Add To Include Path" action, and for that i need absolute paths.
Hello,
say i have a file /var/www/foo/test.php
how do i find out it's path from within it. i'm trying to create an "Add To Include Path" action, and for that i need absolute paths.
This will be provided as a server variable:
$_SERVER["DOCUMENT_ROOT"];
Note: I am leaving my original answer intact, but don't use it. The solutions involving the
__FILE__
constant are preferred.
You can use $_SERVER['DOCUMENT_ROOT']
to find the path to the current script. If you need the name of the .php file included, add on $_SERVER["SCRIPT_NAME"]
, like this:
$_SERVER['DOCUMENT_ROOT'].$_SERVER["SCRIPT_NAME"];
You can use the magic constant, __FILE__
http://us2.php.net/manual/en/language.constants.predefined.php
Try:
dirname(__FILE__);
It will give you the directory in which your currently file is located. File has the full path to your file: http://php.net/language.constants.predefined