我有這樣的代碼放到一個函數(PHP類):的file_get_contents管腔
$theFile = '/test/test.xml'; // these are in the public folder
dd(file_get_contents($theFile));
如果我去mydomain.local/test/test.xml
,給我的工作XML代碼。
但隨着file_get_contents
,我得到這個錯誤:
file_get_contents(/test/test.xml): failed to open stream: No such file or directory
如何解決這個問題?
'的file_get_contents()'相對執行你的PHP腳本(你不會擺弄米如果你有這條路,真正的代碼正確執行,導致laravel如何工作)。使用'base_path()。 「/測試/ test.xml''。 –
@Tezla這個你爲什麼不讀[文檔]不起作用 – Zl3n
宕,(http://laravel.com/docs/5.1/helpers#method-public-path),它是在你所能的公共路徑'public_path( '試驗/的test.xml')'。只是爲了確保'dd'這個代碼,並尋找路徑 - 如果它是正確的,這是你的答案。否則,祝你好運:) - 顯然,我以前的評論不會工作,我假設測試目錄與'app','config',...,'vendor'一起在根目錄下。 –