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);

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 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

markers.xml has permissions set to 777.

Any suggestions on how to solve this problem?

Thank you.

  • Don't set files on your server to be 777; it creates a massive security hole
    – Mike
    Mar 11, 2020 at 10:52

1 Answer 1


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,

  • Thank you for the help. I changed the file permissions and switched it to an absolute path.
    – Laxmidi
    Oct 6, 2011 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.