views:

635

answers:

2

Hello,

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 ?

+2  A: 

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 ??
Wbdvlpr
The file is generated already... I want the user to be able to open the file which will popup a Save As dialogue. But when I open the URL of the XLSX file with window.open, it shows the actually binary of the file in the browser.
Amadeus45
Check updates ...
Wbdvlpr
The first UPDATE did the job... thanks !
Amadeus45
Cheers
Wbdvlpr
A: 

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

AnthonyWJones