【发布时间】:2020-11-07 08:37:54
【问题描述】:
我在我的 laravel 站点中有一个功能,我将表单数据提交到数据库并将提交的图像保存在存储目录中。数据已正确存储在数据库中,但不知何故,图像无法加载,我不知道该怎么办了,因为这已经困扰了我好几天了。
如果有人能看到并告诉我我做错了什么,那就太好了!
我创建了一个符号链接,使用
php artisan link:storage
文件系统.php
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'storage/public',
'visibility' => 'public',
],
带有存储功能的PostController.php:
public function store(Request $request)
{
request()->validate([
'title' => ['required', 'string', 'max:255',],
'thumbnail' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048|unique:posts',
'iframe' => ['required', 'string', 'max:255',],
]);
$image = $request->file('thumbnail');
$originalname = $image->getClientOriginalName();
Storage::disk('public')->put($originalname, file_get_contents($image));
Post::create([
'title' => $request['title'],
'thumbnail' => $originalname,
'iframe' => $request['iframe'],
]);
return redirect()->route('adminPost.index');
}
这就是我尝试加载图像的方式:
<img width="100px" src="{{asset('storage/public/'.$post->thumbnail)}}">
This is where my image is saved This is the path in the browser
【问题讨论】:
-
你的存储路径是
storage/app/public/'.$post->thumbnail
标签: php laravel file-upload laravel-7