xlsx File is corrupted on download in php
<p>I need to download xlsx file in php. The file is downloading but when i open it shows as corrupted file. I used zend Framework</p>

<p><strong>Controller:</strong></p>

<pre><code>$fullPath = '/opt/bitnami/lampstack-5.4.36-0/apps/projects/ProjectName/File_Name.xlsx';

 if ($fd = fopen ($fullPath, "r")) 
 {
   $fsize = filesize($fullPath);
   $path_parts = pathinfo($fullPath);
   $ext = strtolower($path_parts["extension"]);             

   header("Content-type: application/xlsx");
   header("Content-Disposition: attachment;filename=\"".$path_parts["basename"]."\"");
   header("Content-length: $fsize");
   header("Cache-control: private");

   while(!feof($fd)) 
   {
     $buffer = fread($fd, 2048);
     echo $buffer;//To display the file content while downloaded.
    }
   }
   fclose ($fd);
</code></pre>

<p><strong>View:</strong></p>

<pre><code>&lt;?php echo $this-&gt;buffer; ?&gt;
</code></pre>

<p>Other than xlsx/xls file is downloading correctly(PDF/any image file).</p>