Answer the question
In order to leave comments, you need to log in
Generating xls (excel) files in PHP via Spreadsheet_Excel_Writer. Why do I get the contents of the file instead of downloading?
Good afternoon.
I generate an export file, the content is collected correctly, but the file itself is not returned, instead I get the content code, if I save it in xls format via ctrl + s, then excel will open it with a bang, but I need to get exactly the file
Headers are standard for the library
header("Content -type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");
Tried from Habr's article
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' .filesize($file));
The result is the same.
Hosting timeweb, shared.
I copied the Spreadsheet libraries into a slightly different project, everything works as it should, there is VDS.
Any thoughts what is wrong?
Answer the question
In order to leave comments, you need to log in
connect another module. Came out quickly, thanks everyone for the help
// заставляем браузер показать окно сохранения файла
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($savefile));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question