PhpSpreadsheet
PhpSpreadsheet copied to clipboard
Writing file header early when outputting to php://output
This is:
- [X] a feature request
- [X] **not** a usage question
When creating a large spreadsheet (Xlsx for my application but I'm interested in the general case), which is to be sent to the browser via php://output with a Content-disposition header, the user has to wait until the code starts generating output before the browser will see the headers and prompt the user for a download location. If this is several minutes (as in my case) this is a usability headache.
It doesn't require much output to be flushed to the browser to fix this (subject to suitable web server and PHP configuration), indeed in my test code just the "PK" from the file header would be enough. Therefore it would be useful to be able to separate sending the file header, from sending the file content that follows, so that a script could optionally send the header early.
What is the expected behavior?
Something like this would be great:
$spreadsheet = new Spreadsheet();
$writer = new Xlsx($spreadsheet);
header("Content-Disposition: attachment; filename=mytest.xlsx");
$writer->saveHeader("php://output");
// Insert code that generates the spreadsheet content here
$writer->save();