我需要允许用户只流式传输它而不下载该文件我该怎么做?另一个问题这个代码我有问题文件先下载然后播放?
<?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;
}
}
?>