2011-09-17 47 views
0

我在同一個目錄中使用require_once()或include_once()時沒有任何問題。但如果我使用如下:Require_once()和include_once()失敗

我有一個php類的頁面名稱email.class.php其中我已包括下面的代碼。

<?php 
require_once('../../configuration.php'); //The file is outside of directory. (root/system/class/) where the configuration.php file is not in the class directory but in root directory 
?> 

現在我已經在email.class.php包括象下面這樣認購表格。

<?php 
require_once('../class/email.class.php'); // Directory structure is like: (root/system/package/) // the formprocess.php is in the package folder. 
?> 

看來一切正確。但是當我嘗試處理表單時,致命錯誤: require_once無法打開所需的../../configuration.php文件。 然後我試着用URL代替'../..configuration.php'。但我的主機不允許我打開URL。哪裏有問題 ?請幫助我的任何人。我只是一個學習者。

+0

見'GETCWD()'和'真實路徑()' – chelmertz

回答

1

始終使用完整路徑類似require_once(dirname(__FILE__) . '/../../configuration.php');

或者require_once(__DIR__ . '/../../configuration.php'),如果你的PHP版本> = 5.3

+0

我的php版本是5.2 –

+0

因此,使用前一個。 – xdazz

+0

謝謝,這個解決方案對我來說非常合適。我有一個小問題?爲什麼你使用了** dirname(__ FILE __)。'/ ** <---結尾的斜槓('/'在'../'之前)。意味着你爲什麼寫'/../../configuration.php insted'../../configuration.php'。我不知道這件事。 –

0

可能的原因:

  • 你不要讓你的Web服務器訪問特定的目錄
  • 的目錄路徑錯誤(樣式:..對於文件夾/文件夾名稱,取決於當前處理位置

檢查更多的相關信息的幫助.. http://php.net/manual/en/function.require-once.php

相關問題