Search The Hostwinds Guides Knowledge Base

Force Browsers to Download Media Files Instead of Displaying Them

Share This Article [TheChamp-Sharing]

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 method of editing this file. If you have not created a .htaccess file or you’re not certain how to edit this file, please feel free to review our corresponding article which covers this in more detail: Creating and editing an .htaccess file.


How to force a browser to download media files

This method will give users a choice 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 your.htaccess file, web browsers will attempt to download any file extension that matches your .htaccess rule.