Load audio file into html using php -


i have mp3 file stored in location outside web root. able download file using php script, passing bunch of headers. however, want able directly play it, in little audio player embedded in website.

$file = '/location/testfile.mp3'; //this part works fine  header("content-transfer-encoding: binary");  header("content-type: audio/mpeg"); header('content-length: ' . filesize($file)); header('content-disposition: inline; filename="' . basename($file) . '"'); header('x-pad: avoid browser bug'); header('cache-control: no-cache'); 

this code located in tags @ top of page, before tag. within body, want put $file following code playback:

<audio controls>     <source src="<?php echo $file; ?>" type="audio/mp3">     browser not support audio element. </audio> 

i see player, plays sound. however, covers whole page. doing wrong?

i have player plays audio file, try code in php render audio file:

$path = 'some/path/file.mp3'; $ch = curl_init($path); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_header, true); $data = curl_exec($ch); curl_close($ch); if ($data === false) {     echo 'curl failed';     exit; }  if (preg_match('/content-length: (\d+)/', $data, $matches)) {     $contentlength = (int) $matches[1]; }  header('content-transfer-encoding: binary'); header('content-type: audio/mpeg'); header('expires: 0'); header('cache-control: must-revalidate'); header('content-length: ' . $contentlength); ob_clean(); flush(); echo $data; exit; 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -