From 3f11451f3ce6e2ad60ce21a09fb744d3fc02cd5a Mon Sep 17 00:00:00 2001 From: weifashi <605403358@qq.com> Date: Wed, 1 Nov 2023 10:06:56 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E6=96=87=E4=BB=B6=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E5=8A=9F=E8=83=BD=E6=8A=A5500=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Module/Base.php | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/app/Module/Base.php b/app/Module/Base.php index 7a4d3f1cc..1d0c984c6 100755 --- a/app/Module/Base.php +++ b/app/Module/Base.php @@ -2879,26 +2879,31 @@ class Base public static function streamDownload($file, $name = null) { $contentType = 'application/octet-stream'; - if ($file instanceof \Closure) { - $callback = $file; - } else { - if (!$file instanceof File) { - if ($file instanceof \SplFileInfo) { - $file = new File($file->getPathname()); - } else { - $file = new File((string)$file); - } - } - if (!$file->isReadable()) { - 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, [ + // + if ($file instanceof \Closure) { + return Response::streamDownload($file, $name, [ + 'Content-Type' => $contentType, + ]); + } + // + if (!$file instanceof File) { + if ($file instanceof \SplFileInfo) { + $file = new File($file->getPathname()); + } else { + $file = new File((string)$file); + } + } + if (!$file->isReadable()) { + throw new FileException('File must be readable.'); + } + $contentType = $file->getMimeType() ?: $contentType; + $content = $file->getContent(); + return Response::streamDownload(function() use ($content) { + echo $content; + }, $name, [ 'Content-Type' => $contentType, ]); }