title: Symfony2 create and download zip file
body: <p>I have one application that upload some files and then I can compress as zip file and download.</p>
  
  <p>The export action:</p>
  
  <pre><code>public function exportAction() {
          $files = array();
          $em = $this-&gt;getDoctrine()-&gt;getManager();
          $doc = $em-&gt;getRepository('AdminDocumentBundle:Document')-&gt;findAll();
          foreach ($_POST as $p) {
              foreach ($doc as $d) {
                  if ($d-&gt;getId() == $p) {
                      array_push($files, "../web/".$d-&gt;getWebPath());
                  }
              }
          }
          $zip = new \ZipArchive();
          $zipName = 'Documents-'.time().".zip";
          $zip-&gt;open($zipName,  \ZipArchive::CREATE);
          foreach ($files as $f) {
              $zip-&gt;addFromString(basename($f),  file_get_contents($f)); 
          }
  
          $response = new Response();
      $response-&gt;setContent(readfile("../web/".$zipName));
      $response-&gt;headers-&gt;set('Content-Type', 'application/zip');
      $response-&gt;header('Content-disposition: attachment; filename=../web/"'.$zipName.'"');
      $response-&gt;header('Content-Length: ' . filesize("../web/" . $zipName));
      $response-&gt;readfile("../web/" . $zipName);
      return $response;
      }
  </code></pre>
  
  <p>everything is ok until the line header.
  and everytime I'm going here I got the error: "Warning: readfile(../web/Documents-1385648213.zip): failed to open stream: No such file or directory"</p>
  
  <p>What is wrong?</p>
  
  <p>and why when I upload the files, this files have root permissions, and the same happens for the zip file that I create.</p>