阻止浏览器在新浏览器窗口中播放 mp3
有没有办法阻止浏览器在新的浏览器窗口中打开 mp3?
我有一个 mp3 文件的正常链接
<a href="link_to_mp3">some.mp3</a>
,当然您可以右键单击 -> 下载它另存为。但有些用户不知道。因此,如果他们单击链接,则会打开一个新窗口,他们可以在其中收听该 mp3。
问题是,我希望用户下载文件一次,而不是在我的服务器上收听它们数千次;)
is there a way to prevent a browser from opening an mp3 in a new browser window?
i have a normal link to mp3 file like
<a href="link_to_mp3">some.mp3</a>
and of course you can download it with right click -> save as. but some users don't know that. so if they click on a link, a new window opens where they can listen to that mp3.
issue is, i want the users to download the files once instead of listen to them thousand times over my server ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
仅通过 html,您无法强制链接打开文件保存对话框。
相反,您可以通过 PHP 和一些自定义标头来实现这一点 如此处所示
一个简单的 download.php 文件可能如下所示:
您可以在其中指定保存所有文件的目录,以及下载速率(如果需要限制文件下载的速度) 。
更新
忘记提及您将更改链接到:
其中 test.mp3 将更改为您的特定下载
Through html only you cannot force the link to open a file save dialog.
Instead you can achieve that through
PHP
and with some custom headers as seen hereA simple download.php file could look like:
Where you can specify the directory where all your files as saved, as well as a download rate if needed to limit the speed at which the file can be downloaded.
Update
Forgot to mention that you will then change your links to:
where test.mp3 will be changed to your particular download
快速而肮脏:也许你将其压缩...然后浏览器会自动下载该文件
quick and dirty: maybe you .zip it...than the browser automatically downloads the file
谢谢你的剧本。它对我来说不起作用,因为 $local_file 变量构建不正确..不要问,不是真正的 php 专业人士。你的帖子仍然让我朝着正确的方向前进。这是我的解决方案
哦,对于其他 php 傻瓜:脚本开头没有空格!
thanks for your script. it didn t worked out for me, because the $local_file variable wasn't build right.. don t ask, not really a php pro. still your post put me in the right direction. here s my solution
oh, and for other php-dummies: NO WHITESPACE AT THE BEGINNING OF THE SCRIPT!!!