失败,包括

时间:2018-09-03 18:26:38

标签: php nested include

我有一个包含文件的脚本,并且该文件中包含一个文件,例如:

在脚本中:

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

在homepage.php中:

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

我在这里搜索,发现这是一个非常常见的问题,解决方案似乎是使用

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

我具有上述内容,但仍然收到此错误:

警告:include(includes / functions / parent_functions.php):无法打开流:没有此类文件或目录

我已经在运行php 5.5的站点上尝试过此操作,而另一个使用7.2的站点上尝试了此操作-都失败了。如果我使用以下命令打印路径,它将显示正确的完整路径。

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

如上所述,这是一个常见问题,但对于我而言,此修复程序不起作用。谁能看到原因?

1 个答案:

答案 0 :(得分:1)

好吧,您在这里遇到问题。由于parent_functions.php和homepage.php位于同一目录中,因此无需添加额外的目录前缀。您可以简单地使用

FileReader

代替

 include('parent_functions.php');