获取包含文件中当前PHP脚本的名称

时间:2021-08-02 23:44:08

I have files served like so:

我有这样的文件:

AJAX request handler -> Include file

AJAX请求处理程序 - >包含文件

I would like to retrieve the name of the include file within the include itself. Neither $_SERVER['PHP_SELF'] or $_SERVER['SCRIPT_NAME'] is suitable for this, as they return the "parent" script name.

我想在include本身中检索包含文件的名称。 $ _SERVER ['PHP_SELF']或$ _SERVER ['SCRIPT_NAME']都不适用于此,因为它们返回“父”脚本名称。

Thanks.

谢谢。

2 个解决方案

#1


34  

__FILE__

http://us3.php.net/manual/en/language.constants.predefined.php

http://us3.php.net/manual/en/language.constants.predefined.php

#2


22  

If you want only the name part of the file (without the directory) you can use basename(__FILE__) or for just the directory dirname(__FILE__).

如果只想要文件的名称部分(没有目录),可以使用basename(__ FILE__)或仅使用目录dirname(__ FILE__)。

#1


34  

__FILE__

http://us3.php.net/manual/en/language.constants.predefined.php

http://us3.php.net/manual/en/language.constants.predefined.php

#2


22  

If you want only the name part of the file (without the directory) you can use basename(__FILE__) or for just the directory dirname(__FILE__).

如果只想要文件的名称部分(没有目录),可以使用basename(__ FILE__)或仅使用目录dirname(__ FILE__)。