现在我使用这条路线并且它有效:
Route::get('storage/sliders/{filename}', function ($filename)
{
$path = storage_path('app/public/sliders/' . $filename);
if (!File::exists($path)) {
abort(404);
}
$file = File::get($path);
$type = File::mimeType($path);
$response = Response::make($file, 200);
$response->header("Content-Type", $type);
return $response;
});
如果您有其他子目录,您可以使用:
Route::get('storage/{path}/{filename}', function ($path,$filename)
{
$path = storage_path('app/public/'.$path.'/' . $filename);
if (!File::exists($path)) {
abort(404);
}
$file = File::get($path);
$type = File::mimeType($path);
$response = Response::make($file, 200);
$response->header("Content-Type", $type);
return $response;
});