Question

How can I make it so that when a user visits a file in a specified folder, I can force the file to be downloaded?

I know it's possible to do this type by type using .htaccess and you can force a file to download using a php script, but how can I force download the file they visited within the specified folder without a php script?

Currently, when you view a file that the browser knows how to read, it reads the file instead of downloading it. I want it to automatically download all files in the folder instead of reading ones that the browser supports.

Was it helpful?

Solution

The "mod_headers" module should be available.. then you can add this to your .htaccess file.

By type:

<FilesMatch "\.jpg$">
    Header set Content-Disposition attachment
    Header set Content-Type application/octet-stream
</FilesMatch>

A specific file by name:

<Files test.jpg>
    Header set Content-Disposition attachment
    Header set Content-Type application/octet-stream
</Files>

Put it to the .htaccess file in the specific folder with your file to download.

For the whole folder leave out Files/FilesMatch directive.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top