save image in public folder instead storage laravel 5

后端 未结 3 1912
无人及你
无人及你 2020-12-25 14:12

i wanna save my avatar at \"Public\" folder and ther retrieve.

ok. i can save it but in \"storage/app\" folder instead \"public\"

my friend told me go to \"c

3条回答
  •  隐瞒了意图╮
    2020-12-25 14:52

    You can pass disk option to method of \Illuminate\Http\UploadedFile class:

    $file = request()->file('image');
    $file->store('toPath', ['disk' => 'public']);
    

    or you can create new Filesystem disk and you can save it to that disk.

    You can create a new storage disc in config/filesystems.php:

    'my_files' => [
        'driver' => 'local',
        'root'   => public_path() . '/myfiles',
    ],
    

    in controller:

    $file = request()->file('image');
    $file->store('toPath', ['disk' => 'my_files']);
    

提交回复
热议问题