title: Real path of ZF2's public directory
body: <p>I would like to write some data (from a custom controller plugin) into files under the 'messages' subdirectory of my website's public directory.</p>
  
  <p>The custom controller plugin is quite simple:</p>
  
  <pre><code>&lt;?php
  
  namespace Main\Service;
  
  class MessageWriter
  {    
      public $data = array();
  
      public function __set($name, $value)
      {
          $this-&gt;data[$name] = $value;
      }
  
      public function write_message()
      {
          $this-&gt;time = time();
          $data = serialize($this-&gt;data);
  
          $filename = time() . '_' . rand(1000, 9999);
          @file_put_contents('/var/www/public/messages/' . $filename, $data);
      }
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>I have two tiny problems / questions:</p>
  
  <ol>
  <li>How can i avoid the hardcoding of the path? Isn't there a ZF2 config variable which holds the real path of the public directory (/var/www/public).</li>
  <li>Is there any class for writing files in ZF2, or it's OK using file_put_contents and similar file functions?</li>
  </ol>
  
  <p>Thank you very much!</p>
  
  <p>Mike</p>