[英]How can I download a MP4 file instead of playing it on browser?
I have a .mp4 file that I need to download to my system when I click on the anchor tag. 我有一个.mp4文件,当我点击锚标签时,我需要将其下载到我的系统。
HTML: 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. 我需要这个在IE上运行,我唯一的选择是通过javascript或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. 我知道HTML5
download
属性,但它不支持IE。
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. 我发现了这个: http : //www.webdeveloper.com/forum/showthread.php ?244007-RESOLVED-Force-download-of-MP3-file-instead-of- streaming ,我用Excel文件做类似的事情。
Directly from there: 直接从那里:
use a small PHP file to handle the download, put in the same folder as the .mp3: 使用一个小的PHP文件来处理下载,放在与.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>
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. 如果您不能使用dgig提及的服务器端语言,我唯一能做的就是将文件放在ZIP文件中,让用户下载。
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. Apple使用Quicktime样本做到了这一点,因为他们有更多的资金和资源可以投入,我认为这可能是我必须要做的。
如果您能够编写.htaccess
或编辑Apache配置,您还可以检查此建议的响应以强制下载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.