php - Stream protected media (located outside of httpdocs) with jPlayer -
i have uploaded sample mp3 files directory outside of httpdocs, have ensured accessible php configuring open_basedir correctly , tested directory working.
what stream these files via php file non-authenticated users should never have access these files. using jplayer , expect setmedia function should similar this:
$("#jquery_jplayer").jplayer("setmedia", { mp3: "stream.php?track=" + id + ".mp3" });
i have tried setting content headers etc in stream.php , looks this:
$filepath = "../song_files/mp3/"; $filename = "$_get[track].mp3"; header("content-type: audio/mpeg"); header('content-disposition: attachment; filename="'.$filename.'"'); getfile($filepath + $filename);
if load page directly, mp3 file downloads , plays fine, when use above javascript, jplayer doesn't play track.
i have had @ post ( streaming mp3 on stdout jplayer using php ) , appears user trying achieve want, upon testing solution keep running problem, "curl failed".
are there different methods can use achieve this. pointing me in right direction appreciated.
after searching around more have found solution working fine. used code similar topic ( php protect pdf , doc )
i place code used here answer question correctly:
//check users loged in , valid download if not redirect them out // need add code here check // array of support file types download script , there mimetype $mimetypes = array( 'doc' => 'application/msword', 'pdf' => 'application/pdf', ); // set file here (best of using $_get[]) $file = "../documents/file.doc"; // gets extension of file loaded searching array above $ext = explode('.', $file); $ext = end($ext); // gets file name send browser force download of file $filename = explode("/", $file); $filename = end($filename); // opens file reading , sends headers browser $fp = fopen($file,"r") ; header("content-type: ".$mimetypes[$ext]); header('content-disposition: attachment; filename="'.$filename.'"'); // reads file , send raw code browser while (! feof($fp)) { $buff = fread($fp,4096); echo $buff; } // closes file after whe have finished reading fclose($fp); </code></pre>
Comments
Post a Comment