2016-07-02 63 views
-2

我在目录My中有index.php文件。如何在PHP中包含文件?

此文件已包含文件的core/coreEngine.php

里面coreEngine.php我尝试包括另一个文件config/test.php位于上一层目录:

我尝试了所有的情况:

require_once '../config/test.php'; 
require_once '../../config/test.php'; 
require_once '.../config/test.php'; 
+0

[PHP是否包含相对于文件或调用代码的路径?](http://stackoverflow.com/questions/7378814/are-php-include-paths-相对于文件或者调用代码) – FirstOne

+0

你的目录结构对我来说还不清楚,你能否请[提供图表](http://stackoverflow.com/a/3455675/4233593) –

回答

2
My/index.php 
My/core/coreEngine.php <--- you are here 
My/config/test.php  <--- you want to go here 

你想回到M y目录,所以2个目录返回:

require_once '../../config/test.php'; 

但我强烈建议使用绝对路径,而不是相对的路径。您可能想要使用类似于:

require_once($_SERVER['DOCUMENT_ROOT'].'/config/test.php');