0

我在我正在构建的网站上设置了一个下载链接,这样当用户注册到音乐家邮件列表时,他们就可以免费下载曲目。使用此当前代码:

<a href="http://samsouth.com/audio/Mind.mp3">click here to download</a>

当您单击链接时,它在 Firefox 中有效,它会打开一个窗口,询问您是否要下载,但在 Chrome 中,它会流式传输曲目。如果我将文件更改为 .ogg,则会发生相反的情况 - 我可以在 Chrome 中下载,但它会在 Firefox 中流式传输。猜猜这是因为我提供了一种浏览器能够流式传输的格式。那么如何停止它的流式传输呢?我可以提供两个href吗?

在这里寻找类似问题后,我遇到了 html5 属性,该属性可以添加到download="filename.mp3"我尝试过的链接中:

<a  href="http://samsouth.com/audio/Mind.mp3" download="Mind.mp3">click here to download</a>

但它仍然继续在 Chrome 中流式传输,有什么想法吗?请帮忙?

4

2 回答 2

2

可以压缩文件吗?这将避免流式传输。

其他选项

其他一些 PHP 选项:

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

进而

<a href="direct_download.php?file=FILENAME.mp3">Download the mp3</a>
于 2013-08-07T13:15:33.137 回答
0

你可以试试下面的代码吗?

<a href="http://test.com/path/to/my/file.mp3" download="true">download</a>

我认为,它将适用于所有浏览器。

于 2016-11-08T04:15:17.633 回答