将文件保存到laravel中的存储文件夹

问题描述 投票:0回答:1

我将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 未找到错误!

php html laravel webserver storage
1个回答
-1
投票

尝试像这样保存图像:

$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

© www.soinside.com 2019 - 2024. All rights reserved.