August 6, 201313 yr I was hoping someone could help me out here. I just created a new webpage with hostgator and I placed a .htaccess file in the public_html folder to force download of a pdf. For some reason it's not working. I've used the exact same .htaccess file on a webpage through hostgator a couple of years ago and it worked perfectly back then. Here is the script in the file: <Files *.PDF> ForceType application/pdf Header set Content-Disposition attachment </Files> I've also tried: AddType application/octet-stream .pdf What could be wrong? The directory setup of my webpage files? Some sort of conflict between the webpage html and this .htaccess file? Any help on this would be much appreciated. I just spent half a day yesterday looking for answers to this with no luck.
August 6, 201313 yr As opposed to making it viewable in the browser, so the only way the user can view it is by downloading it I'd guess? It sounds a bit dodgy at first but if a large pdf tried automatically opening on a slow connection it could be pointed out as a usability issue and I believe the user would still have to click a link pointing to the file before anything happened. I don't know much about htaccess at all, I didn't even know this was possible until I read this but I've just tried a quick test now and this works for mp3s: <FilesMatch "\.(?i:mp3)$"> ForceType application/octet-stream Header set Content-Disposition attachment </FilesMatch> So is this any better for your pdf? <FilesMatch "\.(?i:pdf)$"> ForceType application/octet-stream Header set Content-Disposition attachment </FilesMatch> The user would still have to click a link but once they did the file would just download rather than opening in their browser. I think... From here: http://www.thingy-ma-jig.co.uk/blog/06-08-2007/force-a-pdf-to-download and here: http://www.saelboat.com/blog/2012/12/htaccess-guide-force-downloads-of-mp3s-pdfs-and-other-media-files-299 Edited August 6, 201313 yr by JustOliver
August 8, 201313 yr I was hoping someone could help me out here. I just created a new webpage with hostgator and I placed a .htaccess file in the public_html folder to force download of a pdf. For some reason it's not working. I've used the exact same .htaccess file on a webpage through hostgator a couple of years ago and it worked perfectly back then. Here is the script in the file: <Files *.PDF> ForceType application/pdf Header set Content-Disposition attachment </Files> I've also tried: AddType application/octet-stream .pdf What could be wrong? The directory setup of my webpage files? Some sort of conflict between the webpage html and this .htaccess file? Any help on this would be much appreciated. I just spent half a day yesterday looking for answers to this with no luck. To force file downloads via .htaccess you must be running on apache.
August 8, 201313 yr Worth reading this - http://css-tricks.com/snippets/htaccess/force-files-to-download-not-open-in-browser/
September 27, 201511 yr Hi FLman, sorry ahead to bump this up but may you please share the steps on how you were able to get this to work? I mean htaccess.
October 20, 201511 yr //original code header ("Content-disposition: attachment; filename=" . str_replace(" ", "_", basename($file)) . ";"); //remove semi-colon from end of contructed file name header ("Content-disposition: attachment; filename=" . str_replace(" ", "_", basename($file)));
Create an account or sign in to comment