Skip to content

Commit

Permalink
https://github.com/aVadim483/fast-excel-templator/issues/9
Browse files Browse the repository at this point in the history
  • Loading branch information
aVadim483 committed Jun 16, 2024
1 parent bf0222e commit 4002d68
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/FastExcelTemplator/Excel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 4002d68

Please sign in to comment.