使用Wordpress plugins_url函数会给出403禁止错误


Using Wordpress plugins_url function gives 403 forbidden error

我正在编写一个插件,并试图获取文本文件的内容。这是有效的:

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

但是,Wordpress Codex表示插件不应该使用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来执行此操作吗?

谢谢

您的服务器可能无法allow_url_fopen或者您可能没有正确编码 URL。 http://php.net/manual/en/function.file-get-contents.php