S
S
syltan-yragan2015-06-11 00:45:26
PHP
syltan-yragan, 2015-06-11 00:45:26

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

3 answer(s)
S
syltan-yragan, 2015-06-12
@syltan-yragan

connect another module. Came out quickly, thanks everyone for the help

W
WarGot, 2015-06-11
@WarGot

Specify in htaccess
AddType application/octet-stream .xls

X
xmoonlight, 2015-06-11
@xmoonlight

// заставляем браузер показать окно сохранения файла
     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 question

Ask a Question

731 491 924 answers to any question