Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache directive for file downloads

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.

like image 707
Boz Avatar asked Nov 08 '11 20:11

Boz


People also ask

How do I make my Apache file downloadable?

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.

What is ServerRoot in Apache configuration?

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.

What is .htaccess file in Apache?

. 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.


1 Answers

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>
like image 200
MRR0GERS Avatar answered Sep 19 '22 05:09

MRR0GERS