我学习了如何编写一个WordPress插件。我需要一些帮助将一些数据写入XML文件。我在我的本地机器上运行MAMP的Mac。我有PHP 5.2.13。在我的插件,我已经有了:PHP fopen()错误:未能打开流:权限被拒绝
$file_handle = fopen('markers.xml', 'w');
$stringdata = "Test Info";
fwrite($file_handle, $stringdata);
fclose($file_handle);
运行上面给了我以下错误:
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
我使用在$ file_handle线的绝对路径的尝试:http://my_site/wp-content/plugins/my_plugin_folder/markers.xml。但是,这并没有奏效。
我也试过改变对markers.xml权限如下:
(我):阅读&写 (未知):只读 大家:读&写
出于某种原因,我Mac不会让我改变(未知)来阅读&写。我不确定这是否有所作为。我右键单击该文件并选择“获取信息”以更改权限。
在phpinfo()函数,我有:
“已注册的PHP流HTTPS,FTPS,compress.zlib,compress.bzip2,PHP,文件,数据,HTTP,FTP”
是一个WordPress设置导致问题?或者它只是PHP的问题?
有关如何解决此问题的任何建议?
谢谢。
的可能的复制[PHP - 未能打开流:没有这样的文件或目录](http://stackoverflow.com/questions/36577020/php-failed-to-open-stream-no-such-file-or-directory) –