Php 具有jPlayer的流保护介质(位于httpdocs之外)

Php 具有jPlayer的流保护介质(位于httpdocs之外),php,streaming,jplayer,Php,Streaming,Jplayer,我已经将一些示例mp3文件上传到httpdocs之外的目录中,通过正确配置open_basedir并测试该目录是否正常工作,我确保PHP可以访问这些文件 我想做的是通过PHP文件流式传输这些文件,因为未经身份验证的用户永远不会访问这些文件。我目前使用的是jPlayer,希望setMedia功能与此类似: $("#jquery_jplayer").jPlayer("setMedia", { mp3: "stream.php?track=" + id + ".mp3" }); 我曾尝试在strea

我已经将一些示例mp3文件上传到httpdocs之外的目录中,通过正确配置open_basedir并测试该目录是否正常工作,我确保PHP可以访问这些文件

我想做的是通过PHP文件流式传输这些文件,因为未经身份验证的用户永远不会访问这些文件。我目前使用的是jPlayer,希望setMedia功能与此类似:

$("#jquery_jplayer").jPlayer("setMedia", { mp3: "stream.php?track=" + id + ".mp3" });
我曾尝试在stream.php中设置内容标题等,目前看起来如下:

$filePath = "../song_files/mp3/";
$fileName = "$_GET[track].mp3";

header("Content-Type: audio/mpeg");
header('Content-Disposition: attachment; filename="'.$fileName.'"');

getFile($filePath + $fileName);
如果我直接加载这个页面,mp3文件可以下载并播放,但是当我使用上面的javascript时,jPlayer不会播放曲目

我看了这篇文章(),似乎用户正试图实现我想要的,但在测试解决方案时,我一直遇到一个问题,我得到的只是“CURL失败”


有什么不同的方法可以实现这一点吗。如果能给我指出正确的方向,我将不胜感激。

在搜索了更多信息后,我找到了一个很好的解决方案。我使用了类似主题()中的代码

我将把我用来帮助正确回答问题的代码放在这里:

//check users is loged in and valid for download if not redirect them out
// YOU NEED TO ADD CODE HERE FOR THAT CHECK
// array of support file types for download script and there mimetype
$mimeTypes = array(
    'doc' => 'application/msword',
    'pdf' => 'application/pdf',
);
// set the file here (best of using a $_GET[])
$file = "../documents/file.doc";

// gets the extension of the file to be loaded for searching array above
$ext = explode('.', $file);
$ext = end($ext);

// gets the file name to send to the browser to force download of file
$fileName = explode("/", $file);
$fileName = end($fileName);

// opens the file for reading and sends headers to browser
$fp = fopen($file,"r") ;
header("Content-Type: ".$mimeTypes[$ext]);
header('Content-Disposition: attachment; filename="'.$fileName.'"');

// reads file and send the raw code to browser     
while (! feof($fp)) {
    $buff = fread($fp,4096);
    echo $buff;
}
// closes file after whe have finished reading it
fclose($fp);
</code></pre>