title: PHP fopen() Error: failed to open stream: Permission denied
body: <p>I learning how to write a WordPress plugin. I need some help writing some data to an XML file. I'm on my local machine, a Mac running MAMP. I have PHP 5.2.13. In my plugin, I've got: </p>
  
  <pre><code>$file_handle = fopen('markers.xml', 'w');
  $stringdata = "Test Info";
  fwrite($file_handle, $stringdata);
  fclose($file_handle);
  </code></pre>
  
  <p>Running the above gives me the following error: </p>
  
  <blockquote>
    <p>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</p>
    
    <p>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</p>
    
    <p>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</p>
  </blockquote>
  
  <p>I tried using the absolute path in the $file_handle line: <a href="http://my_site/wp-content/plugins/my_plugin_folder/markers.xml" rel="noreferrer">http://my_site/wp-content/plugins/my_plugin_folder/markers.xml</a>. But, that didn't work.</p>
  
  <p>I also tried changing the permissions on markers.xml as follows: </p>
  
  <p>(Me): Read &amp; Write
  (unknown): Read only
  everyone: Read &amp; Write</p>
  
  <p>For some reason, my Mac wouldn't let me change (unknown) to Read &amp; Write. I'm not sure if that makes a difference. I right-clicked on the file and selected 'Get Info' in order to change the permissions. </p>
  
  <p>In phpInfo(), I've got: </p>
  
  <p>"Registered PHP Streams     https, ftps, compress.zlib, compress.bzip2, php, file, data, http, ftp"</p>
  
  <p>Is a WordPress setting causing the problem? or is it just PHP issue?</p>
  
  <p>Any suggestions on how to solve this problem?</p>
  
  <p>Thank you.</p>