Home > Enterprise >  Zip files being open as files by APACHE server instead of downloading
Zip files being open as files by APACHE server instead of downloading

Time:10-15

The error that I get is from PHP because APACHE is tryng to pass the .zip file through the PHP interpreter.

But this post is not regarding any PHP script, or setting up headers from PHP to make the file download. It is about preventing APACHE from passing the file through PHP and generate a download instead.

I have found a few answers that involve adding File Exceptions on the .htaccess but still without success and I get the follwing Parse error message:

Parse error: in /home/user/public_html/downloads/files/1/test-file-132110.zip on line 431

CodePudding user response:

These are the .htaccess instructions that I found that work:

<Location "/downloads/files/">
    <Files *.*>
        ForceType application/octet-stream
        Header set Content-Disposition attachment
    </Files>
</Location>

The previous example is not so great because I want to chose specific extensions, lile doc, zip, etc. So I tried these instead:

<Location "/downloads/files/">
  <FilesMatch ".(?i:doc|docx|xls|xlsx|ppt|pptx|zip|rar)$">
     ForceType application/octet-stream
     Header set Content-Disposition attachment
  </FilesMatch>
</Location>

or this, without specifying a location:

<FilesMatch "\.(doc|docx|xls|xlsx|ppt|pptx|zip|rar)$">
    ForceType application/octet-stream
    Header set Content-Disposition attachment
</FilesMatch>
  • Related