How do I create Apache directives in a .htaccess
file that forces .mp4
and .pdf
to download? Currently they appear within the browser window. Instead, I would like a download file dialog box to appear.
Here is an example: Create a file in public_html or www folder and name it download. php Paste the PHP code below and save your file. Now visit http://www.yoursite.com/download.php. The file should download without any issue.
ServerRoot specifies where the subdirectories conf and logs can be found. If you start Apache with the -f (file) option, you need to include the ServerRoot directive.
. htaccess files (or "distributed configuration files") provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.
Add the following into an .htaccess file:
<Files *.mp4>
ForceType application/octet-stream
Header set Content-Disposition attachment
</Files>
<Files *.pdf>
ForceType application/octet-stream
Header set Content-Disposition attachment
</Files>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With