dresh
dresh

Reputation: 403

File with html content served as .xlsx does not get the filename and extension correctly only when downloading in Firefox?

The file gets downloaded with assigned filename and extension correctly when downloaded from Safari or Chrome. I am able to open the file in excel as the OS is able to detect and assign excel as the default program. But when downloaded with firefox, the file does not have the correct Filename or the extension assigned to it. However, after downloading the file the dialogue box to open the file correctly defaults to excel as it is able to recognize the file type. Since the file does not have the correct extension assigned, when I navigate to downloads and then try to open the file it gets opened in text edit.

Here is the code for assigning Filename and Extension in header in PHP:

header('Content-type: application/vnd.openxmlformats- officedocument.spreadsheetml.sheet; charset=utf-8');
header('Content-disposition: attachment; filename='somefile.xlsx');

what could I be missing? I have used the following for reference: Incomplete list of MIME types

another instance of a similar issue

Upvotes: 0

Views: 1398

Answers (2)

Julian Reschke
Julian Reschke

Reputation: 42045

The filename parameter is either unquoted, or in double quotes. It needs quoting when it contains characters outside the HTTP token ABNF (for instance, whitespace, certain delimiters, and non-ASCII).

More in RFC 6266 (https://greenbytes.de/tech/webdav/rfc6266.html)

Upvotes: 0

Ro Achterberg
Ro Achterberg

Reputation: 2704

Your line should not even run as there is an errant single quote:

header('Content-disposition: attachment; filename='somefile.xlsx');

You don't want to quote filename='s value at all. Try this instead:

header('Content-disposition: attachment; filename=somefile.xlsx');

Upvotes: 1

Related Questions