Hostwinds Tutorials

Search results for:


Table of Contents


How to force a browser to download media files

How to Force Browsers to Download Media Files

Tags: htaccess 

How to force a browser to download media files

Generally, most modern-day browsers will attempt to play/stream media files, such as videos, when this type of content is accessed. In some instances, this may be exactly the type of behavior that you'd expect and want. However, this may not always be the case. If you'd like to learn how to ensure that multimedia files are downloaded, then look no further, as the focus of this article is to teach you how to force multimedia files to be downloaded through the browser. This is, of course, accomplished by using a .htaccess file and your favorite editing method. If you have not created a .htaccess file or are not certain how to edit this file, please feel free to review our corresponding article, which covers this in more detail: Creating and editing a .htaccess file.

How to force a browser to download media files

This method will allow users to either save the file or begin playing the file once the file's link is clicked. The following example can be modified to correspond with your specific requirements as needed. This example shows how to force the download of .mp3, mp4, avi, and .png files.

# Tell the browser to download the following multimedia files
AddType application/octet-stream .mp4
AddType application/octet-stream .avi
AddType application/octet-stream .mp3
AddType application/octet-stream .png

You'll need to add this to your .htaccess file, again modifying it as needed. Once added to yours. htaccess file, web browsers will attempt to download any file extension that matches your .htaccess rule.

Written by Michael Brower  /  June 22, 2017