我需要允許用戶流式傳輸它只有該文件沒有下載我該怎麼做? 另一個問題,這個代碼我有問題的文件首先下載然後播放?PHP Stream mp3文件
<?php $file = isset($_GET['q']) ? dirname(__FILE__) . base64_decode($_GET['q']) : false;
$file = urldecode(str_replace('/', '\\', $file));
$download = isset($_GET['d']) ? $_GET['d'] == 't' ? true : false : false;
if ($file) {
$disabelStr = 'DisableTrackDownload-';
$pattern = '/'.$disabelStr.'/';
$disableDownload = preg_match($pattern,$file);
$isFile = is_file($file);
// check if file exists
if($isFile){
// Getting headers sent by the client.
$headers = apache_request_headers();
if(isset($headers['Connection'])){
// stream audio files
header("Content-Type: audio/mpeg");
header('Content-Length:'.filesize($file));
header('Content-Disposition: inline; filename="stream.file"');
header('X-Pad: avoid browser bug');
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Expires: -1");
ob_clean();
flush();
readfile($file);
}else{
// disable download
header ("HTTP/1.0 404 Not Found");
}
exit;
}
}
?>