title: Creating and writing a file in WordPress using PHP
body: <p>I would like to create a file to cache my lookups (coordinates and so on). I don't know why but I cannot create and write to it within WordPress. I am using this code for a try:</p>
  
  <pre><code>&lt;?php
  
   $filename = 'sitevisitors.txt';
  
   if (file_exists($filename)) 
   {
      $count = file(TEMPLATEPATH . 'sitevisitors.txt'); 
      $count[0] ++;
      $fp = fopen(TEMPLATEPATH . "sitevisitors.txt", "w");
      fputs ($fp, "$count[0]");
      fclose ($fp);
      echo $count[0];
   } 
  
   else 
   {
      $fh = fopen(TEMPLATEPATH . "sitevisitors.txt", "w");
      if($fh==false)
          die("unable to create file");
      fputs ($fh, 1);
      fclose ($fh);
      $count = file(TEMPLATEPATH . 'sitevisitors.txt'); 
      echo $count[0];
   }
  
   ?&gt; 
  </code></pre>
  
  <p>I do not get any error message, but the file "sitevisitors.txt" is not created and update and does not appear on my server.
  What am I doing wrong? The path should be ok.
  My server host confirms that I have full privileges. 
  This code works beautifully outside WordPress...</p>
  
  <p>Any suggestion is welcome!</p>
  
  <p>Cheers, Marina</p>