diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 582f23e5e..b423bc0a7 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -223,6 +223,19 @@ class Handler extends ExceptionHandler } catch (\ImagickException) { } } + // 容错处理 + $patternFault = '/^(images\/.*\.(png|jpg|jpeg))\/crop\/([^\/]+)$/'; + $matchesFault = null; + if (preg_match($patternFault, $path, $matchesFault)) { + $file = public_path($matchesFault[1]); + if (!file_exists($file)) { + $file = public_path('images/other/imgerr.jpg'); + } + if (file_exists($file)) { + return response()->file($file); + } + } + return null; } } diff --git a/routes/web.php b/routes/web.php index 42dba4179..403dfb66b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -69,6 +69,6 @@ Route::middleware(['webapi'])->group(function () { Route::any('/{method}', IndexController::class); Route::any('/{method}/{action}', IndexController::class); Route::any('/{method}/{action}/{child}', IndexController::class); - Route::any('/{method}/{action}/{child}/{n}', IndexController::class)->where('method', '^(?!uploads).*'); - Route::any('/{method}/{action}/{child}/{n}/{c}', IndexController::class)->where('method', '^(?!uploads).*'); + Route::any('/{method}/{action}/{child}/{n}', IndexController::class)->where('method', '^(?!(uploads|images)).*'); + Route::any('/{method}/{action}/{child}/{n}/{c}', IndexController::class)->where('method', '^(?!(uploads|images)).*'); });