2012-06-26 38 views
0

我正在寫一個插件,並試圖獲取文本文件的內容。這是工作:使用Wordpress的plugins_url函數給出403禁止的錯誤

$ipn_log = WP_PLUGIN_DIR."/plugin-folder/filename.txt"; 
$log_contents = file_get_contents($ipn_log); 

然而,WordPress的食品法典委員會說,插件不應該使用WP_PLUGIN_DIR,但使用plugins_url函數:http://codex.wordpress.org/Determining_Plugin_and_Content_Directories

所以,我嘗試這樣做:

$ipn_log = plugins_url('filename.txt', __FILE__); 
$log_contents = file_get_contents($ipn_log); 

當我使用plugins_url,我得到一個403禁止的錯誤。任何想法爲什麼?我不應該使用WP_PLUGIN_DIR來做到這一點嗎?

感謝

回答

0

您的服務器可能無法allow_url_fopen或者您可能沒有URL正確編碼。 http://php.net/manual/en/function.file-get-contents.php

+0

allow_url_fopen已啓用,因爲我可以通過其他方式獲取文件內容(請參閱我的問題)。如果我使用WP_PLUGIN_DIR或plugins_url來回顯URL,則它完全相同。 – JROB

+0

通過使用'WP_PLUGIN_DIR',您可以像使用'plugins_url()'時那樣通過路徑獲取文件,而不是通過url。我仍然認爲權限問題來自使用URL。 – Nick

+0

嘗試使用'plugin_dir_path'而不是'plugins_url'。 – Nick