say i have a file
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.
You can use the magic constant,
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:
This will be provided as a server variable:
this_file = $_SERVER"SCRIPT_NAME";
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
__FILE__ outputs exactly what you need.