perf: 图片容错处理

This commit is contained in:
kuaifan
2024-12-12 22:36:25 +08:00
parent 520d2a0e20
commit 29bc009c07
2 changed files with 15 additions and 2 deletions
+13
View File
@@ -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;
}
}