From 76ae3a8c4f537a67529f0b576cf64af6825ecf7d Mon Sep 17 00:00:00 2001 From: Seven Du Date: Mon, 29 Oct 2018 15:37:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(file-storage):=20=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E9=A9=B1=E5=8A=A8=E4=B8=8D=E6=94=AF=E6=8C=81=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E6=92=AD=E6=94=BE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/FileStorage/Filesystems/LocalFilesystem.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/FileStorage/Filesystems/LocalFilesystem.php b/app/FileStorage/Filesystems/LocalFilesystem.php index 01566838a..1d58d75a6 100644 --- a/app/FileStorage/Filesystems/LocalFilesystem.php +++ b/app/FileStorage/Filesystems/LocalFilesystem.php @@ -31,6 +31,7 @@ use Zhiyi\Plus\FileStorage\FileMetaInterface; use Zhiyi\Plus\FileStorage\ResourceInterface; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\BinaryFileResponse; use Illuminate\Contracts\Filesystem\Filesystem as FilesystemContract; class LocalFilesystem implements FilesystemInterface @@ -81,6 +82,7 @@ public function meta(ResourceInterface $resource): FileMetaInterface */ public function response(ResourceInterface $resource, ?string $rule = null): Response { + $realPath = $this->filesystem->path($resource->getPath()); if ($this->meta($resource)->hasImage()) { $rule = new Local\RuleParser($rule); if ( @@ -93,13 +95,12 @@ public function response(ResourceInterface $resource, ?string $rule = null): Res return $this->filesystem->response($resource->getPath()); } - $pathinfo = \League\Flysystem\Util::pathinfo($resource->getPath()); + $pathinfo = \League\Flysystem\Util::pathinfo($realPath); $cachePath = sprintf('%s/%s/%s.%s', $pathinfo['dirname'], $pathinfo['filename'], $rule->getFilename(), $pathinfo['extension']); if ($this->filesystem->has($cachePath)) { return $this->filesystem->response($cachePath); } - $realPath = $this->filesystem->path($resource->getPath()); $image = Image::make($realPath); $image->blur($rule->getBlur()); if (($image->width() > $rule->getWidth() || $image->height() > $rule->getHeight()) && ($rule->getWidth() || $rule->getHeight())) { @@ -114,7 +115,7 @@ public function response(ResourceInterface $resource, ?string $rule = null): Res return $image->response(); } - return $this->filesystem->response($resource->getPath()); + return new BinaryFileResponse($realPath); } /**