PHP流媒体MP3

编程入门 行业动态 更新时间:2024-10-25 12:26:08
本文介绍了PHP流媒体MP3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个非常类似的情况,以问谁: 我可以用PHP提供MP3文件吗? 基本上我试图保护mp3文件免于直接下载,所以用户必须先通过php才能获得认证。 这里是我的代码:

I have a very similar situation to the person who asked: Can I serve MP3 files with PHP? Basically I am trying to protect mp3 files from direct download, so users have to go through php to get authenticated first. Here's my code:

header('Content-type: audio/mpeg'); header('Content-length: ' . filesize($file)); header('X-Pad: avoid browser bug'); Header('Cache-Control: no-cache'); header("Content-Transfer-Encoding: binary"); header("Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3"); readfile($file);

这是我的问题:该文件仅在开始时播放一小部分内容(通过浏览器中的Quicktime ),然后停止 - Quicktime似乎认为文件的长度只与它下载的块大小一样长。当我重新加载 - 它会播放一个更大的块 - 无论它设法下载到那一点。

Here's my problem: The file only plays a very small chunk of the beginning (via Quicktime in the browser) and then stops - Quicktime seems to think the length of the file is only as long as the chunk it managed to download. When I reload - it plays a slightly larger chunk - whatever it managed to download up to that point.

这是我发送的头文件中的问题吗?我将如何流式传输这样的文件? swf从该文件读取时是否存在问题?

Is that a problem in the headers I am sending? How would I stream such a file? Is it a problem if an swf is reading from that file?

谢谢!

谢谢你们所有的答案。虽然这些事情都不是解决问题的办法,但其中许多人都让我朝着正确的方向发展。非常感激。 对于完整的解决方案,请参阅下面的答案

Thank you guys for all the answers. Although none of these things were exactly what solved the problem, many of them sent me in the right direction. Much appreciated. For the full solution see my answer below

推荐答案

>

Here's what did the trick.

$dir = dirname($_SERVER['DOCUMENT_ROOT'])."/protected_content"; $filename = $_GET['file']; $file = $dir."/".$filename; $extension = "mp3"; $mime_type = "audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3"; if(file_exists($file)){ header('Content-type: {$mime_type}'); header('Content-length: ' . filesize($file)); header('Content-Disposition: filename="' . $filename); header('X-Pad: avoid browser bug'); header('Cache-Control: no-cache'); readfile($file); }else{ header("HTTP/1.0 404 Not Found"); }

更多推荐

PHP流媒体MP3

本文发布于:2023-11-01 12:06:39,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:流媒体   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!