2012-02-19 112 views
1

我嘗試,包括我的文件,但由於某種原因,我不能......不能包含我的文件

這裏是我的結構:
enter image description here

index.php,有include_once('includes/php/inc.php'); 。該inc.php包含這些行:

// Required classes 
require_once '../classes/cl_calendar.php'; 

完美正當我想,但由於某種原因,我得到的是這樣的錯誤:

Warning: require_once(../classes/cl_calendar.php): failed to open stream: No such file or directory in /customers/xxx/xxx/httpd.www/new/extra/php/inc.php on line 14 Fatal error: require_once(): Failed opening required '../classes/cl_calendar.php' (include_path='.:/usr/share/php') in /customers/xxx/xxx/httpd.www/new/extra/php/inc.php on line 14 

是什麼讓這個錯誤要顯示和我如何擺脫它?

+0

當然路徑是錯誤的。如果你的index.php位於includes文件夾中(它不應該在那裏),那麼正確的路徑就是'classes/file.php'。 – markus 2012-02-19 14:36:04

+0

'index.php'不在包含文件夾中... – Michiel 2012-02-19 14:36:38

+0

因此,它位於根目錄中。那麼,正確的路徑是'includes/classes/file.php'。爲什麼「..」?這會導致你在根上一級。 – markus 2012-02-19 14:38:36

回答

1

正確的路徑是包含/類/ file.php。爲什麼 ..?這會導致你在根上一級。

其原因是,即使兩個包含文件的相對關係可能是一個不同的,你從索引文件,包括它,因此該路徑必須是相對於索引文件。

1

如果包括從另一個PHP文件,它就像採取這一文件的內容並把它放在你的初始(index.php)文件。所以,當你需要inc.php文件中的更多文件時,它將基於初始文件的路徑。嘗試在index.php文件中設置基本路徑,並在inc.php文件中使用該路徑。嘗試

// index.php 
$base = "/var/www/htdocs/"; 
// or something like dirname(__FILE__) if it may change 
include_once($base.'includes/php/inc.php'); 

// inc.php 
require_once($base.'classes/cl_calendar.php'); 
+0

好的,非常感謝。但是當我嘗試這樣做時,出現以下錯誤:Warning:include_once():open_basedir限制有效。文件(/var/www/htdocs/includes/php/inc.php)不在允許的路徑中:'後面跟着一整列文件 – Michiel 2012-02-19 14:35:48

+0

嘗試將它設置爲相對路徑,如'/'或如果你在一個子目錄中使用'/ sub /'例如並在包含時使用完整路徑。 '$ base ='/'; require_once($ base.'classes/cl_calendar.php');' – 2012-02-19 14:39:19

+0

我不確定我是否明白你的意思...... – Michiel 2012-02-19 14:43:26

0

只需拖放此頁面cl_calendar.php您的index.php頁面,這將顯示然後只要複製完整的href路徑和粘貼,因爲它是在包括作爲HREF鏈接。

或嘗試這一個

require_once(/../classes/cl_calendar.php);