我正在使用 KnpGaufretteBundle 来存储音频文件。我可以像这样将给定的文件下载到客户端:
$filename = "Somefilename.mp3";
$fs = $this->filesystemMap->get('media_fs');
$file = $fs->read($filename);
if($file){
//Create And Return Response
$response = new Response();
$disp = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
$variant->getFileName()
);
$response->headers->set('Content-Length', $fs->size($filename));
$response->headers->set('Accept-Ranges', 'bytes');
$response->headers->set('Content-Transfer-Encoding', 'binary');
$response->headers->set('Content-Type', 'application/octet-stream');
$response->headers->set('Content-Disposition', $disp);
$response->setContent($file);
return $response;
}
但现在我也想将文件流式传输到客户端,而不是使用附件内容配置。基本上,我想在客户端访问它,就好像我指向服务器上的实际 mp3 一样。有谁知道如何做到这一点?