diff --git a/src/FastExcelTemplator/Excel.php b/src/FastExcelTemplator/Excel.php index 788e984..d433d93 100644 --- a/src/FastExcelTemplator/Excel.php +++ b/src/FastExcelTemplator/Excel.php @@ -230,8 +230,24 @@ public function save(?string $fileName = null, ?bool $overWrite = true): bool */ public function download(string $name = null) { + $tmpFile = $this->excelWriter->writer->makeTempFileName(uniqid('xlsx_writer_')); + $this->save($tmpFile); + if (!$name) { + $name = basename($tmpFile) . '.xlsx'; + } + else { + $name = basename($name); + if (strtolower(pathinfo($name, PATHINFO_EXTENSION)) !== 'xlsx') { + $name .= '.xlsx'; + } + } + + header('Cache-Control: max-age=0'); + header('Content-Type: application/vnd.ms-excel'); + header('Content-Disposition: attachment; filename="' . $name . '"'); - $this->excelWriter->download($name); + readfile($tmpFile); + unlink($tmpFile); } /**