2011-12-12 71 views
4

我遇到了set_include_path的問題,我讀了很多關於該問題的消息,但沒有一個適用於我。 我在Debian和我的根目錄將設置爲/ home /項目/PHP set_include_path配置

所以,我想這4個不同的東西:

ini_set("include_path", '/home/project'); 
ini_set("include_path", '.:/home/project'); 
set_include_path('.:/home/project'); 
set_include_path('/home/project'); 
set_include_path(get_include_path().PATH_SEPARATOR.'/home/project'); 

但沒有工作......當我做回聲get_include_path( );每次看起來都很好。

但是第四種方法與我的電腦上的WAMP完美配合。

對所有這些錯誤消息:在使用本

Warning: include(/config/config.php) [function.include]: failed to open stream: No such file or directory in /home/project/web/www.project.com/index.php on line 3 

Warning: include() [function.include]: Failed opening '/config/config.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear:/home/project') in /home/project/web/www.project.com/index.php on line 3 

回答

6

嘗試使用PATH_SEPARATOR常數,因爲它在文檔中完成。

set_include_path(get_include_path() . PATH_SEPARATOR . $path); 

也許它在系統上改變你將應用程序部署到..

UPDATE: 包含路徑似乎是罰款,但問題是不同的東西..

你不應該包括:

require '/config/config.php' 

require 'config/config.php' 

所以放下主導斜線,它應該工作。

+0

是這一個我也試過了,我把它放在列表中... – user1040899

+0

當你試圖包含文件時你能發佈錯誤嗎?它通常會打印出使用的包含路徑。它改變了嗎? –

+0

剛剛編輯我的信息 – user1040899

1

集:set_include_path(get_include_path().PATH_SEPARATOR.'/path/');,這不刪除現有的include_path,被別人腳本設置好的,並添加默認的系統路徑分隔符。

+0

相同的嘗試,沒有成功 – user1040899

1

路徑分隔符可能有所不同。

set_include_path(implode(PATH_SEPARATOR, array(
    '.', 
    '/home/project', 
    get_include_path() 
)); 

有了這個,你得到當前包括附加到你自己加入的影片,併爲每個系統的正確路徑分隔符路徑。

+0

相同,不起作用:-( 它真的很麻煩這個問題... – user1040899