Here is my php code to stream mp3 file through php
set_time_limit(0);
$dirPath = \"path_of_the_directory\";
$songCode = $_REQUEST[\'c\'];
$filePath = $dirPat
Why content-type: application/octet-stream
if it's a song? Change the headers:
set_time_limit(0);
$dirPath = "path_of_the_directory";
$songCode = $_REQUEST['c'];
$filePath = $dirPath . "/" . $songCode . ".mp3";
$strContext=stream_context_create(
array(
'http'=>array(
'method'=>'GET',
'header'=>"Accept-language: en\r\n"
)
)
);
$fpOrigin=fopen($filePath, 'rb', false, $strContext);
header('Content-Disposition: inline; filename="song.mp3"');
header('Pragma: no-cache');
header('Content-type: audio/mpeg');
header('Content-Length: '.filesize($filePath));
while(!feof($fpOrigin)){
$buffer=fread($fpOrigin, 4096);
echo $buffer;
flush();
}
fclose($fpOrigin);
LE: removed Content-Transfer-Encoding
and changed Content-Disposition
from attachment
to inline