我将laravel项目上传到网络服务器(byethost7.com服务器)后,尝试将文件存储到laravel中的storage文件夹中,但文件无法存储到storage文件夹中;只能存储到public文件夹中,
我在cmd上执行了这个命令:
>php artisan storage:link
我的filesystems.php配置:
'public' => [
'driver' => 'local',
'root' => storage_path(),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
'links' => [
public_path('storage') => storage_path('app/public'),
],
图像控制器:
$product=new Product();
$image = $req->file('image');
$image_url = $image->store('images');
$product->image_url = $image_url;
showimages.blade.php:
<img class="img-thumbnail " src="{{asset('storage/images/'.$product->image_url)}}"/>
在 web.php 中:
Route::get('getimages',function(){
return view('showimages');
});
但我总是收到 404 未找到错误!
尝试像这样保存图像:
$imageName = time() . '.' . $request->file->extension();
$request->file->storeAs('public/images/', $imageName);
我希望它有帮助:)
p.s 此链接应该可以帮助您: https://www.itsolutionstuff.com/post/crud-with-image-upload-in-laravel-8-exampleexample.html