doufang6268 2014-02-26 11:33
浏览 55

[复制]中包含的文件名

This question already has an answer here:

I know that sounds confusing, but how do you find the name of the file that another file is included into.

For example, I have two files a.php and b.php. b.php is included into a.php like so:

a.php:

include('b.php');

Now I want code to put into b.php to find the name of a.php. Does that make any sense?

EDIT: Ok, I have come up with a better way to rephrase the question:

How do you get the name of the including file (so in the above example, find the name of file a.php using code in b.php). Does this work?

basename($_SERVER['SCRIPT_FILENAME']);
</div>
  • 写回答

2条回答 默认 最新

  • dongxie8856 2014-02-26 11:39
    关注

    Not sure why you might need it but it's possible using global __FILE__ constant:

    echo basename(__FILE__);
    

    From the documentation about __FILE__:

    The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, FILE always contains an absolute path with symlinks resolved whereas in older versions it contained relative path under some circumstances.

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭