title: Downloading files with Zend Framework
body: <p>I'm a newbie to Zend Framework and I have such problem. On my web page I have the demos of products to be downloaded by users. When they want to download them, they have to fill the form (name, company, e-mail, contact phone) and then click Submit to start downloading. I would like them to be redirected to the product page. Here is my showFormAction code in controller:</p>
  
  <pre><code>    if ($this-&gt;_request-&gt;isPost())
      {
          if (!$form-&gt;isValid($this-&gt;_request-&gt;getPost()))  
          {   
              //shows messages and the form again             
          }               
          else 
          { 
  
              $file = $this-&gt;findYoungestFile('/demo/'.$product.'/');
              $this-&gt;sendFileToClient($file);
              $this-&gt;_redirect('/products/'.$product);
              //sending mail
              $infoMail = new InfoMail($this-&gt;_request-&gt;getPost(), 'download', $product);
              $this-&gt;sendInfoMails($infoMail);                
          }   
      } 
      else
          //show form
  </code></pre>
  
  <p>And here is sendFileToClient function</p>
  
  <pre><code>        header('Content-Description: File Transfer');
          header('Content-Type: application/octet-stream');
          header('Content-Disposition: attachment; filename='.basename($file));
          header('Content-Transfer-Encoding: binary');
          header('Expires: 0');
          header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
          header('Pragma: public');
          header('Content-Length: ' . filesize($file));
  
          readfile($file); 
  </code></pre>
  
  <p>The redirection doesn't work. I suppose there is a problem with headers sent to the browser, but I don't know how to solve it. Could anyone help me, please?</p>
  
  <p>Thanks &amp; regards,
  Malgorzata</p>