【发布时间】:2015-12-24 17:19:38
【问题描述】:
我在使用 Laravel 4.2 提供 mp3 时遇到了一些问题 我有一些文件应该由 flashplayer 播放。
public function get($filename)
{
$file = new Symfony\Component\HttpFoundation\File\File(storage_path().DbConfig::get('system.upload_dir').'/'.DbConfig::get('system.upload_music').'/'.$filename);
$response = Response::make(file_get_contents(storage_path().DbConfig::get('system.upload_dir').'/'.DbConfig::get('system.upload_music').'/'.$filename));
$response->header('Content-Type', $file->getMimeType());
$response->header('Content-Length', $file->getSize());
$response->header('Content-Transfer-Encoding', '');
$response->header('Accept-Range', 'bytes');
$response->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
$response->header('Connection', 'Keep-Alive');
return $response;
}
这为文件提供服务 - 如果在 chrome 中打开,它会启动 chrome 的默认播放器并播放音乐,同样的事情是当我用 flashplayer 播放它时。
但是我无法上弦。 如果我使用 apache(而不是 Laravel 控制器)提供文件,它可以正常工作。
如果有人能帮助我解决这个问题,我将不胜感激。
更新
通过 Laravel 提供的标头:
HTTP/1.1 200 OK
Date: Thu, 01 Oct 2015 18:43:59 GMT
Server: Apache/2
Cache-Control: must-revalidate, post-check=0, pre-check=0, private
Content-Transfer-Encoding:
Accept-Range: bytes
Connection: Keep-Alive, Keep-Alive
Set-Cookie: laravel_session=eyJ[...]D; expires=Thu, 01-Oct-2015 20:44:00 GMT; Max-Age=7200; path=/; httponly
Vary: Accept-Encoding,User-Agent
Keep-Alive: timeout=2, max=100
Transfer-Encoding: chunked
Content-Type: audio/mpeg
在没有 Laravel 的情况下提供的标题:
HTTP/1.1 200 OK
Date: Thu, 01 Oct 2015 18:51:16 GMT
Server: Apache/2
Last-Modified: Fri, 13 Mar 2015 04:03:23 GMT
ETag: "ead61-5112394e338c0"
Accept-Ranges: bytes
Content-Length: 961889
Keep-Alive: timeout=2, max=100
Connection: Keep-Alive
Content-Type: audio/mpeg
【问题讨论】:
-
在这种情况下,“风”是什么意思?我建议您记录您在 Apache 和 Laravel 中收到的响应标头并将它们发布在这里,以便我们可以看到有什么不同。
-
@bernie 看看我的更新,“wind”表示我可以使用播放器栏跳过记录的某些部分,稍后我可以将其倒回到开头。
标签: php laravel audio laravel-4 httpresponse