title: readfile() function read the zip file instead of Downloading it (Zend)
body: <p>I have to trigger a download of a zip file ( The Zip file is inside my data folder).
  For this i am using the code,</p>
  
  <pre><code>$file = 'D:\php7\htdocs\Project\trunk\api\data\file.zip';
  header('Content-Description: File Transfer');
  header('Content-type: application/zip');
  header('Content-disposition: attachment; filename=' . basename($file) );
  readfile($file);`
  </code></pre>
  
  <p>This is working in core php as i expected. But when i am using the same code in the Zend prints a content like below,</p>
  
  <p><code>PKYsVJ)~�� study.xlsPKYsVJs�����+
  tutorial-point-Export.xlsPKYsVJn��� 8��Zabc.xlsP</code></p>
  
  <p>In between the content i can see the name of all files in the zip. But it is not getting downloaded.</p>
  
  <p>After i realised that this is not working i started searching about it and Found some solution from stack over flow</p>
  
  <p><strong>Try 1:</strong> Adding different header element and <code>ob</code> functions in every random lines</p>
  
  <ul>
  <li><code>header('Content-Transfer-Encoding: binary');</code></li>
  <li><code>header('Expires: 0');</code></li>
  <li><code>header('Cache-Control: must-revalidate, post-check=0, pre-check=0');</code></li>
  <li><code>header('Pragma: public');</code></li>
  <li><code>header('Content-Length: ' . $file_size);</code></li>
  <li><code>ob_start();</code></li>
  <li><code>ob_clean();</code></li>
  <li><code>flush();</code></li>
  </ul>
  
  <p>All these are tried from different stack overflow Question and answers and have the same result</p>
  
  <p><strong>Try 2:</strong><a href="https://stackoverflow.com/questions/9995582/php-is-reading-file-instead-of-downloading">PHP is reading file instead of downloading</a> . This question do not have any accepted answer   (He was asking about the core php but i have the same issue with zend only) . I tried all of this but it was not working.</p>
  
  <p><strong>Try 3:</strong><a href="https://stackoverflow.com/a/13306373/6643185">Changing the .htaccess</a> . After that i thought it was a problem with my .htaccess and found this answer for changing the .htaccess file. </p>
  
  <pre><code>&lt;FilesMatch "\.(?i:zip)$"&gt;
          ForceType application/octet-stream
          Header set Content-Disposition attachment
  &lt;/FilesMatch&gt;
  </code></pre>
  
  <p>This also given me the same result.</p>
  
  <p><strong>Try 4:</strong><a href="https://stackoverflow.com/questions/15219873/force-download-using-zf2">Using download functions in Zend</a> . I have tried the all the zend functions in the answer of this question. But given me an empty output even the file was not read.</p>
  
  <p><strong>Try 5:</strong> Remove all the unwanted spaces before and after the php tag as per the <a href="https://stackoverflow.com/a/22228190">answer</a></p>
  
  <p>Is there any other way to trigger a download in ZF2 framework?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Below is my exact function. This is GET(API) function,</p>
  
  <pre><code>public function getList(){
      try{
         //here i am getting the zip file name.
         $exportFile = $this-&gt;getRequest()-&gt;getQuery('exportid','');
         $file = 'D:\php7\htdocs\Project\trunk\api\data\\' . $exportFile . '.zip';
         header('Content-Description: File Transfer');
         header('Content-type: application/zip');
         header('Content-disposition: attachment; filename=' . basename($file) );
         readfile($file);
         return new JsonModel(["status"=&gt;"Success"]);
      } catch(\Exception $e){
         return new JsonModel(["status"=&gt;"Failed"]);
      }
  }
  </code></pre>