我正在尝试让mp3在我的网站上通过左键下载,而不是右击和另存为,所以为了做到这一点,我必须设置Content-Disposition: attachment。这是我的第一个网站,所以我对如何实际做到这一点是新手,但是我是在我的html标记中这样做,还是在我的托管网站上以某种方式设置呢?
下面是我的标记的一个示例。
<div class="download">
<a href="MP3/Morgan Page, Sultan & Ned Shepard, and BT feat. Angela McCluskey.mp3"
<img src="img/dlicon.png"/></a>
</div>发布于 2012-01-16 13:43:56
MP3列表示例:
<a href="download.php?file=testing.mp3">Download MP3</a>
<a href="download.php?file=testing2.mp3">Download MP3</a>download.php:
<?php
$file = $_GET['file'];
header('Content-type: audio/mpeg');
header('Content-Disposition: attachment; filename="'.$file.'"');
?>发布于 2014-03-27 20:54:16
正如其他人所说,在HTML中不能做到这一点,动态解决方案(例如,使用PHP)过于夸张。
在您的示例中,我将在web服务器配置中配置Content-Disposition头。对于Apache,您可以设置头文件based on location,或者使用与某些文件名匹配的.htaccess文件。
发布于 2014-07-12 17:28:51
在PHP中也有一个特殊的函数:
bool http_send_content_disposition ( string $filename [, bool $inline = false ] )
请参阅PHP :http://de2.php.net/manual/en/function.http-send-content-disposition.php
https://stackoverflow.com/questions/8875949
复制相似问题