/** * Faz o stream do arquivo. * * @throws Exception */ public function streamFile() { $mimetype = $this->Mimetype->getType($this->filepath); if (FALSE === $mimetype) { throw new Exception('Extensão não suportada.'); } // Headers para stream de arquivo header('Content-Description: File Transfer'); header('Content-Type: ' . $mimetype); header('Content-Disposition: attachment; filename=' . basename($this->filepath)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($this->filepath)); ob_clean(); flush(); // Lê o arquivo para stream buffer readfile($this->filepath); }