Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

Making ALL files in a directory available for download through a "save-as" dialog box

I have a number of files in my "/files" directory that I would like to make available for download, through links on my site.

Some are ZIP files, some are word documents, some are images and some are HTML documents.

As it is right now, if someone clicks on a link to a ZIP file, a dialog box asks them if they wish to save the file to disk.  But if they click on an image or an HTML document, it opens it up in the browser.   I want this dialog box for ALL files in the /files directory, not just for applications.

Can I do this by controlling headers with .htaccess?  If so, how?

Thanks!
Avatar of periwinkle
periwinkle
Flag of United States of America image

As I understand it, what happens when a user gets a download file will depend upon how their computer itself if configured, not on how you configure things on the server.  Basically, depending upon the doc type, the user's computer will handle using the handler that they have registered.
Avatar of rmharwood
rmharwood

You can do it this way (I think):

Place the entry

    ForceType application/octet-stream

in the .htaccess file in your /files directory.
Avatar of hankknight

ASKER

Thanks, rmharwood.

You have the right idea, this is what I want to do.

I created a file called ".htaccess" and placed it in the directory but files are still being shown through the browser instead of being downloaded.
Ok... your server configuration must allow you to override the "FileInfo" options using .htaccess files. Are you the admin of the server? If not you will need to ask if you can do this. They'll need to add

    AllowOverride FileInfo

into their Apache config in the approproate place.
Yes, I have root access.

What are the security implications of me making the change you suggested?
ASKER CERTIFIED SOLUTION
Avatar of rmharwood
rmharwood

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What is the name of the global config file?
>  What is the name of the global config file?

httpd.conf
(usually)

I guess you've not edited this before? If you've got access to the config file anyway you could put

    ForceType application/octet-stream

in the global config file in place of "AllowOverride..." and then you don't even need a .htaccess file.