Laravel可恢复下载


Laravel Resumable Download

我的PHP脚本正在使用Laravel的响应::download函数将zip文件下载给用户:

$file    = public_path(). "/storage/rhcloud/lobby/0.1.zip";
$downloadName = "lobby-0.1";
$headers = array(
   'Content-Type: application/zip',
);
return Response::download($file, $downloadName, $headers);

下载工作正常。但是,无法执行暂停/恢复下载功能。

我在网上找遍了,但什么也没找到。Laravel是否支持这种部分内容下载,或者应该使用本地PHP代码而不是Laravel的代码?

即使我添加了额外的代码,我如何使Response::download函数从用户请求标头的给定字节中获取数据?

如果不指定内容长度(即文件大小),浏览器不知道如何或从哪里恢复下载。此外,您可以使用basename()函数从完整路径获取文件名,无需对其进行硬编码

试试这个:

$file    = public_path(). "/storage/rhcloud/lobby/0.1.zip";
$headers = [
   'Content-Type' => 'application/zip',
   'Content-Length' => filesize($file)
];
return Response::download($file, basename($file), $headers);

或者,对于旧的Laravel版本,如OP,请尝试:

$file    = public_path(). "/storage/rhcloud/lobby/0.1.zip";
$headers = array(
   'Content-Type: application/zip',
   'Content-Length: '. filesize($file)
);
return Response::download($file, basename($file), $headers);