2013-11-15 38 views
2

所以我不知道是什麼原因我的代碼不能正常工作去了一個目錄,但這裏是錯誤,我得到:不能夠使用使用simplexml_load_file

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "../../setting.xml" in /home1/sk8ermid/public_html/MVP/themes/SDS-2013/home.php on line 3 

這裏是我使用的代碼:

<?php 

$settings = simplexml_load_file('../../setting.xml'); 
$site_title = $settings->title; 

?> 

我想上去兩個「settings.xml」文件所在的目錄。我是以正確的方式做到這一點,還是有另一種方式來做到這一點?

回答

1

試試這個

$settings = simplexml_load_file(__DIR__ . '/../../setting.xml'); 

在我始終保持這.(該CWD)是PHP腳本的目錄在任何include/require樹的根,只有當你的配置include_path實際上包括.(儘管這可以在代碼中進行更改,但默認情況下是這樣做的)。

如果您的home.php腳本被其他腳本包含在其他目錄中,則.與該其他腳本相關。

使用__DIR__確保始終從當前腳本的父目錄開始。

請參閱