WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 0 down vote accepted

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,

share|improve this answer
Thank you for the help. I changed the file permissions and switched it to an absolute path. – Laxmidi Oct 6 '11 at 19:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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