下载的MP3,而不是默认的浏览器中播放? [英] download mp3 instead of playing in browser by default?
问题描述
我有一个网站,用户可以在Flash播放器流我的音乐或下载每首歌曲(如MP3音乐)。现在,如果你点击下载链接,他们只是在浏览器中播放。我可以使它所以下载会弹出默认情况下没有任何荏苒使用户室温的文件。点击?
我有我有看起来像这样的链接index.php页面(从MySQL拉动动态文件名:
<表>
。
。
。
&所述; TD>
< PHP的包括媒体/'。 $行[型。 '/'。 $行['FOLDER_NAME']。 /download.php'&GT?;
< / TD>
然后的download.php有这个:
< DIV CLASS =downloadCell>
< H3>下载:< / H3 GT&;
< UL>
<立GT;
< A HREF =auto_download.php路径=媒体/<?PHP的echo $行['类型']'/'$行['FOLDER_NAME']>?/Chemtengure.mp3> Chemtengure< / A>
< /李>
< / UL>
< / DIV>
和我把auto_download.php在同一目录中的index.php:
auto_download.php:
$ PATH = $ _GET ['路径'];
标题(内容处置:附件;文件名='基本名($ PATH));
ReadFile的($ PATH);
您需要把这个HTTP头添加到您的响应,使浏览器强制下载:
内容处置:附件;文件名= your_filename.mp3
例如,如果您正在使用服务器端PHP,你可以创建一个发送上述头后面是实际的文件内容的脚本:
$ PATH = $ _GET ['路径'];
标题(内容处置:附件;文件名='基本名($ PATH));
ReadFile的($ PATH);
如果你调用这个脚本的download.php
,然后链接到的download.php?路径= /路径/要/你/ file.mp3
将会使浏览器弹出一个下载对话框 file.mp3
。
I have a site where users can stream my music from a flash player or download the individual songs (as mp3s). Right now if you click on the download links, they just play in the browser. Can I make it so the download box will pop up by default without either zipping the files making the user rt. click?
I have my index.php page with the links looking like this (pulling file names dynamically from mySQL:
<table>
.
.
.
<td>
<?php include 'Media/' . $row['type'] . '/' . $row['folder_name'] . '/download.php' ?>
</td>
and then download.php has this:
<div class="downloadCell">
<h3>Downloads:</h3>
<ul>
<li>
<a href="auto_download.php?path=Media/<?php echo $row['type'] . '/' . $row['folder_name'] ?>/Chemtengure.mp3">Chemtengure</a>
</li>
</ul>
</div>
and I put the auto_download.php in the same directory as index.php:
auto_download.php:
$path = $_GET['path'];
header('Content-Disposition: attachment; filename=' . basename($path));
readfile($path);
You will need to add this HTTP header to your response to make the browser force a download:
Content-Disposition: attachment; filename=your_filename.mp3
For example, if you're using PHP on the server side, you can create a script that sends the above header followed by the actual file contents:
$path = $_GET['path'];
header('Content-Disposition: attachment; filename=' . basename($path));
readfile($path);
If you call this script download.php
, then linking to download.php?path=/path/to/your/file.mp3
will make the browser pop-up a download dialog for file.mp3
.
这篇关于下载的MP3,而不是默认的浏览器中播放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!