2012-07-09 119 views
1

當一切工作正常時,我已經創建了與以前相同的超級簡單腳本。但不知何故停了,現在每次我嘗試需要一個文件時,它給我的錯誤:require_once致命錯誤(多一次)

Fatal error: require_once(): Failed opening required 'E:\tools\EasyPHP\www/registry/registry.class.php' (include_path='.;C:\php\pear') in E:\tools\EasyPHP\www\index.php on line 18

我的索引文件:

define("APP_PATH", dirname(__FILE__)."/"); 
require_once(APP_PATH.'registry/registry.class.php'); 

這就是一切,但我仍然無法加載頁面。

我應該如何設置它?我只使用Windows本地構建。

+0

file_exists(APP_PATH.'registry/registry.class.php')給出了什麼?如果爲false,則根據文件的預期路徑檢查APP_PATH.'registry/registry.class.php' – Ing 2012-07-09 14:14:21

+3

可能是愚蠢的問題,但存在'E:\ tools \ EasyPHP \ www/registry/registry.class.php'嗎? – Florent 2012-07-09 14:15:20

+0

是的,但它表明,它甚至不存在。 – user1512181 2012-07-09 14:23:49

回答

3
define("APP_PATH", dirname(__FILE__) . DIRECTORY_SEPARATOR); 
require_once(APP_PATH . 'registry' . DIRECTORY_SEPARATOR . 'registry.class.php'); 

DIRECTORY_SEPARATOR評估反斜槓在Windows系統中,並在* nix系統斜槓。這樣,您的代碼就可以在Windows和Linux環境下無需修改即可運行。

See the PHP manual on this constant及其朋友PATH_SEPARATOR。)

如果您還是有問題,很可能該文件並不在這條道路的存在,或者PHP沒有讀權限的文件。

+0

噢,這太棒了:) – 2012-07-09 14:25:39

+0

無法打開需要'E:\ tools \ EasyPHP \ www \ registry \ registry.class.php'(include_path =' 。; C:\ php \ pear') 雖然文件實際存在並且具有所有保存/讀取/寫入權限。 – user1512181 2012-07-09 14:26:33

1

你在你的dirname()字符串的結果看到了\和你的另一字符串你有/,我想你應該只有\

+0

我什麼都沒做,我只設置/分隔符,反斜槓已被系統添加到文件。 theres甚至沒有辦法改變它 – user1512181 2012-07-09 14:20:24

+0

在windows中,您使用\在PHP中的文件路徑,當用PHP編寫。所以你應該寫:'define(「APP_PATH」,dirname(__ FILE __)。「\」); require_once(APP_PATH.'registry \ registry.class.php');' – 2012-07-09 14:23:05