Closed yogeshsaroya closed 1 year ago
PHP_XLSX_Writer uses ZipArchive, which writes a temporary file to the server. So there is always a temporary file saved on the server at some point.
I wrote this method to download file:
public function download(string $filename){
$buffer = $this->writeToString();
header('Content-Description: File Transfer');
if (headers_sent())
$this->Error('Some data has already been output to browser, can\'t send XLSX file');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Content-Type: application/force-download');
header('Content-Type: application/octet-stream', false);
header('Content-Type: application/download', false);
header('Content-Type: application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', false);
if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
// don't use length if server using compression
header('Content-Length: '.strlen($buffer));
}
header('Content-disposition: attachment; filename="'.$filename.'"');
print $buffer;
}
@NitemareReal Thank you!
@mk-j How to download file in post method without saving file at server?