2017-04-02 80 views
0

嗨所以在我的主家目录我有2个子目录:subDir_AsubDir_B。在subDir_A有一个名为file_a.php。在subDir_B我有一个文件file_b.php的文件。在file_b.php我想在包括file_a.php。它是否可能?我正在使用Xamp。 enter image description herePHP:是否可以包含兄弟目录中的文件?

+0

include_once(../ subDir_A/file_A.php) –

回答

0

是的。

在file_B.php:include('../subDir_A/file_A.php');

../意味着你要上去一个目录。

1

使用4种功能之一很容易完成。

includeinclude_oncerequirerequire_once,请参阅本http://php.net/manual/en/function.include.php文档(我不会在此展开,因为它是非常基本的PHP功能)

你应该做你包括以下方式。

# you could use any of the other keywords as well. 
include __DIR__ . '/../subDir_A/file_A.php'; 

魔术常量__DIR__使用,因为它会考虑相对的参考,它被称为在文件中。如果你不这样做,只是做include '../subDir_A/file_A.php';,如果你提供file_B.php别的地方可能无法正常工作因为它将与调用它的父文件相关。

相关问题