如何制作可供下载的视频文件?

时间:2013-06-14 21:40:53

标签: html href

我正在尝试在我的网站上提供视频的下载选项。 我有直接链接(有.mp4 / .webm结尾)可供下载(如果重要的话,它们不会托管在我的服务器上)。 这就是我试过的:

     <a href="http://stream.flowplayer.org/bauhaus/624x260.webm" download>Download</a>

它仅适用于Chrome,在FireFox中它只会在浏览器上打开视频。

4 个答案:

答案 0 :(得分:1)

您需要一个包装器脚本,它适当地设置Content-Type Content-Disposition标头,并输出您想要提供的文件。

在PHP中,这将是这样做的:

文件名:624x260.php

<?php
// We'll be outputting a webm video
header('Content-type: video/webm');

// It will be called downloaded.webm
header('Content-Disposition: attachment; filename="download.webm"');

readfile('624x260.webm');
?>

然后您将链接到PHP文件,如下所示:

<a href="624x260.php">Download</a>

答案 1 :(得分:0)

HTML5添加了您在示例中所拥有的下载属性,但该属性为空。为下载属性添加一个值,然后将其添加到presto中。

即在您的标签中更改下载内容=“624x260.webm”。

http://updates.html5rocks.com/2011/08/Downloading-resources-in-HTML5-a-download

对于非HTML5兼容的浏览器,最直接的方法是在链接中指向“右键单击下载”的方向。这将涵盖大多数案例和浏览器。

这里概述了几种技术,我意识到你无法压缩文件。

http://webdesign.about.com/od/beginningtutorials/ht/download_link.htm

有许多方法可以做到这一点,包括修改Web服务器配置,但不是每个人都有访问/专有技术来做到这一点。

答案 2 :(得分:0)

注意:Chrome 14+和Firefox 20+支持下载属性。

作为其他浏览器的替代方案,您可以从此处使用jQuery插件 http://johnculviner.com/jquery-file-download-plugin-for-ajax-like-feature-rich-file-downloads/4

OR

http://jqueryfiledownload.apphb.com/

您可以将其下载为

<a href="http://video.webmfiles.org/elephants-dream.webm" class="download" target="_blank">Download</a>

        $(document).on("click", "a.download", function () {
            $.fileDownload($(this).prop('href'))
                .done(function () { alert('File download a success!'); })
                .fail(function () { alert('File download failed!'); });

            return false;
        });

答案 3 :(得分:0)

如果您碰巧有一个可以编辑.htaccess文件的apache服务器,请添加此行。

AddType application/octet-stream .webm

如果你不想这样做,你也可以通过php做到这一点。

PHP代码:

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

HTML代码:

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