Zanshin13
Zanshin13

Reputation: 1066

Firefox downloads(tries to open) .zip file as .HTM

I am creating downloadable zip file, it works fine almost everywhere. But in Mozilla Firefox on save of this zip I get strange message that my_zip.zip is HTM file (sorry for the language, but I hope it is pretty understandable):
enter image description here
If I choose save option it will be saved as normal zip (no sign of HTM at all), but in "open as" section there are only programms for opening HTM

So, the question is How to make Firefox detect this zip as zip?
I am currently using this headers (set by PHP):

        header('Content-Description: File Transfer');
        header("Content-Type: application/octet-stream");
        header("Content-Disposition: attachment; filename=$zipFileName");
        header("Content-Transfer-Encoding: binary");
        header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
        header("Cache-Control: no-store");
        header('Pragma: no-cache');
        header("Content-length: " . filesize($zipFileName));
        readfile($zipFileName);

Already tried using header("Content-Type: application/zip"); , does not work; plus application/zip is not standart (as I read here in some headers related question).

I am using Mozilla Firefox v40.0.3, the php project is using Laravel 5.1 (I doubt it has anything to do with this)


UPDATE:
While trying different application\[format]s , I added a dump and die command after headers

        //bunch of kosher headers here...
        readfile($zipFileName);
        dd(headers_list());//dumps and dies

And I get a zip type in download window. Then I figured out that after die or exit I will always get right download type of zip; Then I deleted all dump-and-die sections , but download type remains as zip. I have no idea what i have fixed by this manipulations.
I would love to have an explanation of this strange situation

Upvotes: 2

Views: 1320

Answers (1)

gyaani_guy
gyaani_guy

Reputation: 3209

A quick google search suggests the Content-Type seems to be the culprit

 header("Content-Type: application/octet-stream");

Try setting it to application/x-zip-compressed ? ALso the comments in this bug report may be useful: https://bugzilla.mozilla.org/show_bug.cgi?id=540900

Upvotes: 2

Related Questions