in file.php
:
call()...
How to get absolute path of f开发者_开发百科ile.php
inside call()
?
Pay attention that call()
may be defined in another file.
another.php
:
function call(){..}
file.php
:
include(path_to_another.php);
call();
no way except debug_backtrace
function whatever() {
$t = debug_backtrace();
echo "called from {$t[0]['file']}";
}
In addition to James Brooks's answer and Bretticus observation, if you need to get the basename
of the calling file you can do:
$backtrace = debug_backtrace();
$file_name = basename($backtrace[0]['file']);
You can also get the basename for the file, like so;
basename(__FILE__);
Hope this helps!
精彩评论