I’m trying to write to an XML file in a WordPress Plugin. I’m on my local machine, a Mac running MAMP. I have PHP 5.2.13 My code is:
$file_handle = fopen('markers.xml', 'w');
$stringdata = "Test Info";
fwrite($file_handle, $stringdata);
fclose($file_handle);
I get 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 73Warning: 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 75Warning: 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
markers.xml has permissions set to 777.
Any suggestions on how to solve this problem?
Thank you.
Check folder permissions too.
Also See this post http://www.php.net/manual/en/function.fopen.php#105465 – suggests he had to change to absolute from relative to get around error message.
Set of debug suggestions here:
http://www.wrensoft.com/forum/showthread.php?t=786
1) folder permissions
2) upper/lowercase
3) abs/relative path
and finally it turned out to be an extra space somewhere,