/** * Send file download response */ public function download($path = '') { $this->flushHeaders(); $this->flushContents(); if (!empty($path)) { if (Validate::isUrl($path)) { $this->redirect($path); } if (is_file($path) !== true) { $this->setText(404, '404: The requested file could not be found.'); $this->send(); } $file = new File($path); $this->cacheExpire('-1 week'); $this->setStatusCode(200); $this->setContentType($file->getMimeType()); $this->setHeader('Content-Description', 'File Transfer', true); $this->setHeader('Content-Disposition', 'attachment; filename=' . $file->getSafeName() . ';', true); $this->setHeader('Content-Length', $file->getSize(), true); $this->setHeader('Content-Transfer-Encoding', 'binary', true); $this->sendHeaders(); @readfile($file->getPath()); exit; } throw new Exception('Tried to download a file without providing a valid file path.'); }