最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I download a MP4 file instead of playing it on browser? - Stack Overflow

programmeradmin0浏览0评论

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.

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.

Share Improve this question edited Feb 17, 2022 at 16:21 Luca Kiebel 10.1k7 gold badges32 silver badges46 bronze badges asked Apr 22, 2015 at 14:07 AwesomestviAwesomestvi 8031 gold badge7 silver badges14 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 3

I found this: http://www.webdeveloper./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>

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.

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

发布评论

评论列表(0)

  1. 暂无评论