【发布时间】:2010-03-13 11:34:25
【问题描述】:
在file.php:
call()...
如何在call()中获取file.php的绝对路径?
注意call()可能定义在另一个文件中。
another.php:
function call(){..}
file.php:
include(path_to_another.php);
call();
【问题讨论】:
在file.php:
call()...
如何在call()中获取file.php的绝对路径?
注意call()可能定义在另一个文件中。
another.php:
function call(){..}
file.php:
include(path_to_another.php);
call();
【问题讨论】:
除了debug_backtrace没有办法
function whatever() {
$t = debug_backtrace();
echo "called from {$t[0]['file']}";
}
【讨论】:
$_SERVER['REQUEST_URI']。使用我的函数root(),我可以轻松获取到根目录的'../../ 路径。 @user187291,你的回答让我开始了;谢谢!
除了 James Brooks 的回答和 Brettcus 的观察,如果你需要获取 调用文件的basename 你可以这样做:
$backtrace = debug_backtrace();
$file_name = basename($backtrace[0]['file']);
【讨论】:
【讨论】: