title: Yii2 - download corrupted file
body: <p>I am working on existing products and i am trying to resolve problem with downloading xlsx file.
  When i download file through file manager, file is allright. But when i download file through Yii app, the file is corrupted.</p>
  <p>Here is my code</p>
  <pre><code>public function actionCallLog($hash, $filename)
      {
          var_dump(
              $hash, $filename
          );
  
          ignore_user_abort(true);
          set_time_limit(0);
          
  
          $path = &quot;/var/www/html/uploads/call_log/&quot;.$hash.'/';
  
          $dl_file= basename($filename).'.xlsx';
          if (!file_exists($path.$dl_file)) {
              $dl_file= basename($filename).'.csv';
          }
          $fullPath = $path.$dl_file;
  
          if ($fd = fopen ($fullPath, &quot;r&quot;))
          {
  
              $fsize = filesize($fullPath);
              $path_parts = pathinfo($fullPath);
              $ext = strtolower($path_parts[&quot;extension&quot;]);
              switch ($ext)
              {
                  case &quot;xlsx&quot;:
                  header('Content-Description: File Transfer');
                  header(&quot;Content-type: application/xlsx&quot;);
                  header(&quot;Content-Disposition: attachment; filename=\&quot;&quot;.$path_parts[&quot;basename&quot;].&quot;\&quot;&quot;);
                  break;
                  case &quot;csv&quot;:
                  header('Content-Description: File Transfer');
                  header(&quot;Content-type: application/csv&quot;);
                  header(&quot;Content-Disposition: attachment; filename=\&quot;&quot;.$path_parts[&quot;basename&quot;].&quot;\&quot;&quot;);
                  break;
                  // add more headers for other content types here
                  default;
                  header('Content-Description: File Transfer');
                  header(&quot;Content-type: application/octet-stream&quot;);
                  header(&quot;Content-Disposition: filename=\&quot;&quot;.$path_parts[&quot;basename&quot;].&quot;\&quot;&quot;);
                  break;
              }
              header(&quot;Content-length: $fsize&quot;);
              header(&quot;Cache-control: private&quot;);
              header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
              header('Expires: 0');
              header('Pragma: public');
              while(!feof($fd))
              {
                  $buffer = fread($fd, 2048);
                  echo $buffer;
              }
          }
          fclose ($fd);
          exit;
      }
  </code></pre>
  <p>Does anybody know where can be the problem?
  <br>Thanks</p>