下载音频/mpeg mime 类型的文件
我正在尝试下载具有音频/mpeg mime 类型的远程 mp3 文件,而不是右键单击链接然后另存为。我尝试使用 php 标头修改标头内容类型,然后使用 readfile() 调用该文件。这工作得很好,但由于 readfile() 命令,文件超出了我的服务器带宽。是否有另一种方法可以在不消耗带宽的情况下更改标头?我可以用 javascript 定义浏览器如何处理内容类型吗?有人遇到同样的问题吗?
提前致谢。
I am trying to download remote mp3 files with an audio/mpeg mime type instead of right clicking on the link then saving as. I have tried modifying the header content-type with php headers and then calling the file with readfile(). This worked very well but because of the readfile() command the files came out of my servers bandwidth. is there another way of changing the header without the cost of bandwidth? can i define how the browser handles with content type with javascript? has anyone had the same problem?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过使用 mime 类型 audio/mpeg,您可以告诉浏览器“对此文件执行默认操作”。例如,如果您有一个 jpg 文件并将 mime 类型设置为 image/jpeg,则浏览器将读取该 jpg 并将其显示在浏览器窗口中。
解决方案是改用 mime 类型 application/data。这将下载文件,而不会浏览器。
这将是
==更新==
一个更完整的方法
如果你想要一个动态mime类型阅读器你可以使用这个
并且,要获取mime类型列表你可以检查我的实验室版本,保存显示的内容并将其保存到网站根目录下名为 mime.types 的文件中。
http://www.trikks.com/lab/mime.html
玩得开心
By using the mime type audio/mpeg you tell the browser to "do your default action with this file". In example if you have an jpg file and set the mime type to image/jpeg the browser will read the jpg and display it inside the browser window.
The solution is to use the mime type application/data instead. This will download the file leaving the browser out of it.
That would be
== Updated ==
A more complete approach
If you want a dynamic mime type reader you could use this
And, to get a list of mime types you can check my lab version, save the displayed content and save it to a file named mime.types in the root of your website.
http://www.trikks.com/lab/mime.html
Have fun
我认为您需要做的是:
使用
Content-Disposition: Attachment...
强制显示下载框,而不必右键单击 ->将目标另存为。I think what you need to do is this:
Using
Content-Disposition: attachment...
forces a download box to appear instead of having to right click -> save target as.