Monday 9 July 2012

Force files not to open in browser Apache

Sometimes you may not want to allow the user the to open the file in the browser and provide them option to open or save.Following links will be helpful.
http://css-tricks.com/snippets/htaccess/force-files-to-download-not-open-in-browser/
       AddType application/octet-stream .pdf
http://www.stuvel.eu/pdfdownload
       SetEnvIf Request_URI "\.pdf$" requested_pdf=pdf
       Header add Content-Disposition "attachment" env=requested_pdf
http://www.thingy-ma-jig.co.uk/comment/5305
      <FilesMatch "\.(?i:pdf)$">
            ForceType application/octet-stream
            Header set Content-Disposition attachment

      </FilesMatch>


Don't forget to enable the mod_header module in apache. If not enabled, will get 500 internal server error.
The first method works only in certain browsers. After doing the changes, always restart the apache and clear the browser cache.

No comments:

Post a Comment