How can I download a MP4 file instead of playing it on browser?

Vishal Chauhan picture Vishal Chauhan · Apr 22, 2015 · Viewed 8.1k times · Source

I have a .mp4 file that I need to download to my system when I click on the anchor tag.

HTML:

<a href="DSCSA_webinar.mp4">Download Here</a>

Is there any way to download this instead of opening it in a browser?

I needed this to run on IE as well and the only option I have is through javascript or jQuery. Anything else that is simpler can also be suggested.

I am aware of the HTML5 download attribute, but it doesn't support on IE.

Answer

dgig picture dgig · Apr 22, 2015

I found this: http://www.webdeveloper.com/forum/showthread.php?244007-RESOLVED-Force-download-of-MP3-file-instead-of-streaming and I do similar things with Excel files.

Directly from there:

use a small PHP file to handle the download, put in the same folder as the .mp3:

<?php
$file = $_GET['file'];
header ("Content-type: octet/stream");
header ("Content-disposition: attachment; filename=".$file.";");
header("Content-Length: ".filesize($file));
readfile($file);
exit;
?>

which can be accessed in any anchor like this:

<a href="direct_download.php?file=fineline.mp3">Download the mp3</a>