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'];
精彩评论