代码之家  ›  专栏  ›  技术社区  ›  user3052443

nexted includes失败

  •  0
  • user3052443  · 技术社区  · 6 年前

    我有一个脚本,其中包含一个文件,该文件中包含一个include,如下所示:

        include('includes/functions/homepage.php);
    

    在主页.php:

        include('includes/functions/parent_functions.php');
    

        include(dirname(__FILE__) . '/includes/functions/homepage.php');
    

    警告:include(includes/functions/parent)_函数.php):无法打开流:没有这样的文件或目录

    我在一个运行PHP5.5的站点和另一个使用7.2的站点上尝试过这个方法,但在这两个站点上都失败了。如果我使用以下命令打印路径,它将显示正确的完整路径。

        echo dirname(__FILE__) . '/includes/functions/homepage.php';
    

    1 回复  |  直到 6 年前
        1
  •  1
  •   Rinsad Ahmed    6 年前

    你有个问题。作为父母_函数.php以及主页.php在同一个目录中,您不需要添加额外的目录前缀。你可以简单地使用

     include('parent_functions.php');
    

    include('includes/functions/parent_functions.php');