2017-04-02 112 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別的地方可能無法正常工作因爲它將與調用它的父文件相關。

相關問題