从浏览器的流停止MP3文件 [英] Stop mp3 file from streaming in browsers

查看:167
本文介绍了从浏览器的流停止MP3文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Apache服务器上的MP3。我想,当一个用户访问该链接,它被下载为文件。相反的QuickTime,或谷歌铬合金媒体播放器将尝试和流吧。

I have an mp3 on an apache server. I want it to be downloaded as a file when a user visits the link. Instead quicktime, or google chromes media player will try and stream it.

是否有此页眉修复?或者是唯一的选择让右键另存为?

Is there a fix for this with headers? Or is the only option so 'right click save as'?

修改这里是我的头。 Safari浏览器已经停止流,但镀铬contines去做。
Chrome浏览器似乎忽略了这一点:

Edit Here is my header. Safari has stopped streaming, but chrome contines to do it. Chrome seems to be ignoring this:

我可以看到标题已正确更改:

I can see the header has been changed correctly:

Date    Wed, 04 Aug 2010 00:14:35 GMT
Server  Apache/2.2.13 (Unix) mod_ssl/2.2.13 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.2.11
Last-Modified   Tue, 03 Aug 2010 04:37:01 GMT
Etag    "2bbd692-79597d-48ce3de3f5540"
Accept-Ranges   bytes
Content-Length  7952765
Content-Disposition attachment
Keep-Alive  timeout=5, max=100
Connection  Keep-Alive
Content-Type    audio/mpeg

还有什么在头,将导致此?

Is there anything else in the header that would cause this?

修改做一些研究,我发现这一点:的http://www.google.com/support/forum/p/Chrome/thread?tid=76de4f53f43f03d3&hl=en
看起来有可能是在Chrome $ P $的一个错误,从下载pventing它。

Edit Doing some research I found this: http://www.google.com/support/forum/p/Chrome/thread?tid=76de4f53f43f03d3&hl=en Looks like there might be a bug in chrome preventing it from downloading.

推荐答案

您要设置的 内容处置 响应头为附件,也可能是文件名栏中为好。

You want to set the Content-Disposition response header to "attachment", and probably the "filename" field as well.

例如:

Content-Disposition: attachment; filename=foo.mp3;

要直接在Apache中做到这一点,尽量把你的的httpd.conf 的.htaccess 文件如下:

To accomplish this directly in Apache, try putting the following in your httpd.conf or .htaccess file:

<FilesMatch "\.(?i:mp3)$">
  ForceType audio/mpeg
  SetEnvIf Request_URI "^.*/?([^/]*)$" FILENAME=$1
  Header set Content-Disposition "attachment; filename=%{FILENAME}e"
  UnsetEnv FILENAME
</FilesMatch>

编辑:

添加文件名外地Apache配置为例,从<借来的href=\"http://serverfault.com/questions/101948/how-to-send-content-disposition-headers-in-apache-for-files/101966#101966\">this回答。你应该知道,然而,由于与在其中非US-ASCII字符的文件名可能出现的问题:看<一个href=\"http://stackoverflow.com/questions/93551/how-to-en$c$c-the-filename-parameter-of-content-disposition-header-in-http\">this问题。

Added filename field to Apache configuration example, borrowed from this answer. You should be aware, however, of potential problems caused by filenames with non-US-ASCII characters in them: see this question.

另外,你可以使用一个通用的文件名不变(因为你已经知道分机),如 Song.mp3的,但是这可能不是根据您的情况的选项。

Alternatively, you could use a generic constant filename (since you know the extension already) like song.mp3, but this might not be an option depending on your circumstances.

第三个选择是创建一个脚本来为这些MP3音乐,可设置页眉并采取剥离不需要的字符出了名的照顾。

A third option would be to create a script to serve these MP3s, which can set the header and take care of stripping unwanted characters out of the filename.

这篇关于从浏览器的流停止MP3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆