title: Php zend framework forcedownload
body: <p>I should set up a simple download manager
  and I don't understand whay this code doesn't work:</p>
  
  <pre><code>protected function doDownload($filename){
          //$this-&gt;_helper-&gt;layout()-&gt;disableLayout();
          //$this-&gt;_helper-&gt;viewRenderer-&gt;setNoRender(true);
          $dir = Zend_Registry::get('dir');
          $file = $dir-&gt;assets.$filename;
          if(file_exists($file)){
              $response = $this-&gt;getResponse();
              $response-&gt;setHeader('Content-Description','File Transfer', true);
              $response-&gt;setHeader('Content-Type','application/octet-stream', true);
              $response-&gt;setHeader('Content-Disposition','attachment; filename='.basename($file), true);
              $response-&gt;setHeader('Content-Transfer-Encoding','binary', true);
              $response-&gt;setHeader('Expires','0', true);
              $response-&gt;setHeader('Cache-Control','must-revalidate, post-check=0, pre-check=0', true);
              $response-&gt;setHeader('Pragma','public', true);
              $response-&gt;setHeader('Content-Length: ' , filesize($file),true);
              ob_clean();
              flush();
              readfile($file);
              exit(0);
            /*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));
              ob_clean();
              flush();
              readfile($file);
              exit(0);*/
  
           }
  
  
      }
  </code></pre>
  
  <p>while with the commented code the script works fine.</p>