This guide explains how to download files upon a click on a link. In general, a file URL will open in a browser when you click on it. Instead, it is simple to make files download immediately after clicking.
Let us follow the steps:
- Open the .htaccess file in the File Manager to make changes.
- To make all of your desired file extensions downloadable when someone clicks the link, add the following line of code:
AddType application/octet-stream .avi .mpg .mov .pdf .xls .mp4 - For instance, the line of code might seem as follows if you only wanted the .pdf files to be downloadable:
AddType application/octet-stream .pdf - Now, “Save” the changes.
- The changes will take effect. If you cannot see the changes on your live site, clear the cache.
This way, you can download files upon a click on a link.
If you want to explore more advanced ways, Check out our guide on How to download a file using curl command