2012-04-30 63 views
1

路徑我看了一些其他相關的問題,並認爲這是最好的答案:不能得到正確的包括PHP

set_include_path(get_include_path().PATH_SEPARATOR."/path/to/program/root"); 

但是,我不能得到正確的目錄和錯誤信息沒有足夠的幫助,所以我迷路了。我的用戶區域目錄(共享主機)看起來是這樣的:

/home/linweb09/b/example.com-1050560306/user # <-- this is my root 

我試圖讓所有的模型文件在這個目錄重新組織我的計劃:

{root}/program_name/library/ 

的基於web根文件夾是這樣的:

{root}/htdocs/ 

所以我改變了我所有的包括看起來像這樣:

set_include_path(get_include_path().PATH_SEPARATOR 
       ."/home/linweb09/b/example.com-1050360506/user"); 
require_once "/program_name/library/some_module.php"; 

該指數已加載該包括對工作,對用戶進行認證:

/htdocs/admin/authenticate.php 
# index.php 
set_include_path(get_include_path().PATH_SEPARATOR 
       ."/home/linweb09/b/example.com-1050360506/user"); 
require_once "/htdocs/admin/authenticate.php"; 

而且我碰到這些錯誤:

[warn] mod_fcgid: stderr: PHP Fatal error:
require_once() [function.require]: Failed opening required '/htdocs/admin/authenticate.php'
(include_path='.:/usr/share/pear:/usr/share/php:/home/linweb09/b/example.com-1050360506/user')
in /home/linweb09/b/example.com-1050360506/user/htdocs/admin/index.php on line 3

[warn] mod_fcgid: stderr: PHP Warning:
require_once(/htdocs/admin/authenticate.php) [function.require-once]: failed to open stream:
No such file or directory in
/home/linweb09/b/example.com-1050360506/user/htdocs/admin/index.php on line 3

但它是在正確的位置和錯誤說沒有這樣的文件或目錄,所以我不知道我應該如何配置這個。

我也嘗試過這些,我得到了同樣的錯誤:

set_include_path(get_include_path().PATH_SEPARATOR."/user"); 
set_include_path(get_include_path().PATH_SEPARATOR."/"); 

回答

1

嘗試刪除斜線。 /htdocs/admin/authenticate.php意味着您正在從根/開始工作。如果你想它來搜索包含路徑,則需要使用相對路徑:

require_once "program_name/library/some_module.php"; 
require_once "htdocs/admin/authenticate.php"; 

順便說一句,你只需要設置包括路徑一旦每個腳本 - 你不需要的set_include_path()線,用於對包括,只是一次在腳本的頂部。

+0

我嘗試過'/','user /'和'(full-path)'作爲set_include_path,我試過了'htdocs/admin/authenticate.php',但還是沒有運氣:( – Ozzy

+0

其實,你是完全正確的!我只是再次檢查日誌文件,另一個包括我需要更新的失敗,謝謝你的幫助:)。 (對於我之後的其他人,它使用全路徑,即'/ home/linweb09 /.../user' – Ozzy