Beispiel #1
0
 /**
  * @param string $filename Local filename to be send.
  * @param string $name     Filename to be shown to client.
  * @param int    $status
  * @param array  $headers
  */
 public function __construct($filename, $name = null, $status = 200, array $headers = [])
 {
     if (empty($name)) {
         $name = basename($filename);
     }
     //Forcing default set of headers
     $headers += ['Content-Disposition' => 'attachment; filename="' . addcslashes($name, '"') . '"', 'Content-Transfer-Encoding' => 'binary', 'Content-Type' => 'application/octet-stream', 'Content-Length' => (string) filesize($filename), 'Expires' => '0', 'Cache-Control' => 'no-cache, must-revalidate', 'Pragma' => 'public'];
     parent::__construct(fopen($filename, 'rb'), $status, $headers);
 }
 /**
  * {@inheritdoc}
  */
 public function getBody()
 {
     $body = parent::getBody();
     if (!empty($this->view)) {
         if ($body->isWritable()) {
             //Let's render view content
             $body->write($this->view->render());
         }
         $this->view = null;
     }
     return $body;
 }