我學習瞭如何編寫一個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) –