setFilePath($file); } } /** * * set real path to the file to be downloaded * * @param string $filePath * @return $this */ public function setFilePath($filePath) { $this->_filePath = realpath($filePath); return $this; } /** * * get real file path * * @return string */ public function getFilePath() { return $this->_filePath; } /** * * if the file exists, create a download request and stop all other executions * * @return null|mixed */ public function send() { if (($filePath = $this->getFilePath()) !== false) { $this->setHeader('Content-Type: application/octet-stream') ->addHeader('Content-Disposition: attachment; filename="' . basename($filePath) . '"') ->addHeader('Content-Length: ' . filesize($filePath)); $this->setBody( readfile($filePath)); parent::send(); exit(0); } return null; } }