Get filename of file which ran PHP include

后端 未结 7 2185
后悔当初
后悔当初 2020-11-28 11:47

When using the PHP include, how can I find out which file is calling the include? In short, what is the parent\'s file filename?

7条回答
  •  猫巷女王i
    2020-11-28 12:25

    I was searching same information on web for complement my online course about php and found two ways. The first was

    $file = baseline($_SERVER['PHP_SELF']);
    echo $file;  //that outputs file name
    

    BUT, in include or require cases it gets the final file that it's included or required. Also found this, the second

    $file = __FILE__;
    echo $file; //that outputs the absolute way from file
    

    BUT i just was looking for the file name. So... I mix it up and it worths well!

    $file = basename(__FILE__);
    echo $file; //that outputs the file name itself (no include/require problems)
    

提交回复
热议问题