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

落爺英雄遲暮 提交于 2019-12-08 05:57:50

问题


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.


回答1:


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>



回答2:


I've run into this with video files (I want to offer a download, but the browser always tries to open it).

If you can't use a server-side language like dgig mentions, the only thing I've been able to do is put the file in a ZIP file and let the user download that.

Apple does this with Quicktime samples, and since they have more money and resources to throw at this than I do, I figured that was probably how I'd have to do it.




回答3:


If you are able to write an .htaccess or edit the Apache config, you can also check this proposed response to force a download.



来源:https://stackoverflow.com/questions/29800166/how-can-i-download-a-mp4-file-instead-of-playing-it-on-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!