开发者

How to echo the name of a file from code in an included file

开发者 https://www.devze.com 2023-03-27 11:10 出处:网络
I want to return the name of the first file being processed in the stack. Let me explain: I\'ve got two files.

I want to return the name of the first file being processed in the stack.

Let me explain: I've got two files.

1) foo:

include("bar");

开发者_开发百科2) bar:

echo __ FILE__;

When I request foo it displays "/home/example/bar" while I'd like to see the string "/home/example/foo" happening.

How to do that?


The __FILE__ constant by design is ALWAYS the file where the constant appears, regardless of what file(s) have loaded/included this file. Try $_SERVER['SCRIPT_NAME'] instead.


This should do the trick:

$backtrace = debug_backtrace();
echo $backtrace[0]['file'];

http://php.net/manual/en/function.debug-backtrace.php


This should do the trick:

echo $_SERVER['SCRIPT_FILENAME'];
0

精彩评论

暂无评论...
验证码 换一张
取 消