Amadeus45
Amadeus45

Reputation: 1228

Firefox : Open XLSX file not saving file butn opening binary

I generate a file server side and I want the client to automatically open it : it's a XLSX file. Firefox just opens the file and I see the binary content of the XLSX file in the browser, but I want it to be open via a Save As... box.

It works fine in Chrome with the same code (it saves it) but not firefox...

Any ideas ?

Upvotes: 0

Views: 4267

Answers (2)

TigerTiger
TigerTiger

Reputation: 10806

Have a look at this - Php exec and return binary

Are you sending proper headers?? something like

header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"yourfile.xlsx\"");

UPDATE

header('Content-Type: application/xls');
header('Content-Disposition: attachment; filename=example.xlsx');
header('Pragma: no-cache');
echo file_get_contents("/path/to/yourfile.xlsx");

UPDATE 2

Spread sheet mime types

application/vnd.ms-excel [official]
application/msexcel
application/x-msexcel
application/x-ms-excel
application/vnd.ms-excel
application/x-excel
application/x-dos_ms_excel
application/xls

UPDATE 3

Regarding your javascript problem did you try using

location.href instead of window.open ??

Upvotes: 4

AnthonyWJones
AnthonyWJones

Reputation: 189495

You need to ensure you are sending this mime type as the Content-Type header:-

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

So you need to map the .xslx extension to this mime type on the server

Upvotes: 0

Related Questions