好了,你可以创建一个使用
php artisan storage:link
和访问文件,使用
<img src="{{ asset('public/myfolder1/image.jpg') }}" />
符号链接
但有时候,如果您在共享主机上,则无法创建符号链接。您希望保护某些访问控制逻辑背后的某些文件,可以选择具有读取和提供映像的特殊路径。例如。
Route::get('storage/{filename}', function ($filename)
{
$path = storage_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;
});
现在你可以像这样访问你的文件。
http://example.com/storage/public/myfolder1/image.jpg
<img src="{{ asset('storage/public/myfolder1/image.jpg') }} />
注:我建议不存储在数据库中的灵活性的路径。请只存储文件名并在代码中执行以下操作。
Route::get('storage/{filename}', function ($filename)
{
// Add folder path here instead of storing in the database.
$path = storage_path('public/myfolder1' . $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;
});
,并使用
http://example.com/storage/image.jpg
希望帮助:)
''你尝试访问? – imrealashu
@imrealashu输出包括我的根目录在内的整个路径。像这样:'/ home3/eisenheim/myproject_src/storage // public/myfolder1/FxEj1V1neYrc7CVUYjlcYZCUf4YnC 84Z3cwaMjVX.png' – Eisenheim
请检查我的答案我认为这会有所帮助。我通常在我的共享主机上使用它。 – imrealashu