簡體   English   中英

PHP fopen()錯誤:無法打開流:權限被拒絕

[英]PHP fopen() Error: failed to open stream: Permission denied

我學習如何編寫WordPress插件。 我需要一些幫助將一些數據寫入XML文件。 我在我的本地機器上,一台運行MAMP的Mac。 我有PHP 5.2.13。 在我的插件中,我有:

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

運行上面的代碼給出了以下錯誤:

警告:fopen(markers.xml)[function.fopen]:無法打開流:第73行/Users/my_name/Sites/my_site/wp-content/plugins/my_plugin_folder/my_plugin_main_file.php中的權限被拒絕

警告:fwrite():提供的參數不是第75行/Users/my_name/Sites/my_site/wp-content/plugins/my_plugin_folder/my_plugin_main_file.php中的有效流資源

警告:fclose():提供的參數不是76行/Users/my_name/Sites/my_site/wp-content/plugins/my_plugin_folder/my_plugin_main_file.php中的有效流資源

我嘗試使用$ file_handle行中的絕對路徑: http://my_site/wp-content/plugins/my_plugin_folder/markers.xml 但是,這沒有用。

我還嘗試更改markers.xml的權限,如下所示:

(我):讀寫(未知):只讀大家:讀寫

出於某種原因,我的Mac不會讓我改變(未知)讀寫。 我不確定這是否有所作為。 我右鍵單擊該文件並選擇“獲取信息”以更改權限。

在phpInfo()中,我得到了:

“已注冊的PHP Streams https,ftps,compress.zlib,compress.bzip2,php,file,data,http,ftp”

是WordPress設置導致問題? 還是只是PHP問題?

有關如何解決這個問題的任何建議?

謝謝。

您可能需要以管理員身份更改權限。 在Mac上打開終端,然后打開markers.xml所在的目錄。然后鍵入:

sudo chmod 777 markers.xml

系統可能會提示您輸入密碼。 此外,它可能是不允許完全訪問的目錄。 我不熟悉WordPress,因此您可能需要將每個目錄的權限更改為mysite目錄。

[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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM