fix:文件下载功能报500修复

This commit is contained in:
weifashi 2023-11-01 10:06:56 +08:00
parent 0b888b9597
commit 3f11451f3c

View File

@ -2879,9 +2879,16 @@ class Base
public static function streamDownload($file, $name = null)
{
$contentType = 'application/octet-stream';
if ($name && !str_contains($name, '.')) {
$name .= ".";
}
//
if ($file instanceof \Closure) {
$callback = $file;
} else {
return Response::streamDownload($file, $name, [
'Content-Type' => $contentType,
]);
}
//
if (!$file instanceof File) {
if ($file instanceof \SplFileInfo) {
$file = new File($file->getPathname());
@ -2893,12 +2900,10 @@ class Base
throw new FileException('File must be readable.');
}
$contentType = $file->getMimeType() ?: $contentType;
$callback = $file->getContent();
}
if ($name && !str_contains($name, '.')) {
$name .= ".";
}
return Response::streamDownload($callback, $name, [
$content = $file->getContent();
return Response::streamDownload(function() use ($content) {
echo $content;
}, $name, [
'Content-Type' => $contentType,
]);
}