I have Drupal website and my users can no longer download files. (docx, xlsx, etc). In firefox only, when the user clicks a link to download a file the page displays garbage code.
I read elsewhere the solution is to add the following, but it didn’t work. Instead, the user is prompted with a dummy download for the application type each time the page reloads.
drupal_set_header(‘Content-type: application/octet-stream; charset=utf-8’);
I have a simple module which has a page that spits out the links to the files. In this module I added the above to the hook_init() function.

I’ve never encountered this problem before, and I’m not sure why it started. Any help would of course be greatly appreciated. If I find a solution before someone replies with the answer I’ll post it here for future reference.
This happens because MIME types are not set correctly.
You can either force Drupal to set the
content-type headerto appropriate MIME type, or set it at the server side.I’d recommend you to do it in the .htaccess file in your files folder (sites/default/files by default)
Just put the below code in the .htaccess file (or you can create a new .htaccess file if it’s not there).
Note that hook_init() gets fired at every normal page request. Never do this in this hook or you will end up facing many problems.