PHPfopen()错误:failed to open stream: Permission denied?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (140)

我学习如何编写一个WordPress插件。我需要一些帮助将一些数据写入XML文件。我在我的本地机器上运行MAMP的Mac。我有PHP 5.2.13。在我的插件中,我有:

$file_handle = fopen('markers.xml', 'w');
$stringdata = "Test Info";
fwrite($file_handle, $stringdata);
fclose($file_handle);

运行上述给我以下错误:

Running the above gives me the following error:

Warning: fopen(markers.xml) [function.fopen]: failed to open stream: Permission denied in /Users/my_name/Sites/my_site/wp-content/plugins/my_plugin_folder/my_plugin_main_file.php on line 73 Warning: fwrite(): supplied argument is not a valid stream resource in /Users/my_name/Sites/my_site/wp-content/plugins/my_plugin_folder/my_plugin_main_file.php on line 75 Warning: fclose(): supplied argument is not a valid stream resource in /Users/my_name/Sites/my_site/wp-content/plugins/my_plugin_folder/my_plugin_main_file.php on line 76

提问于
用户回答回答于

需要以管理员身份更改权限

sudo chmod 777 markers.xml
用户回答回答于

[function.fopen]: failed to open stream

如果你有权访问php.ini文件,启用Fopen。找到相应的行并将其设置为“on”:&如果在wp中,例如php.ini中的localhost / wordpress / function.fopen:

allow_url_fopen = off
should bee this 
allow_url_fopen = On

And add this line below it:
allow_url_include = off
should bee this 
allow_url_include = on

扫码关注云+社区

领取腾讯云代金券