简体   繁体   English

如何将图像保存在 laravel 存储目录中

[英]How to save image in laravel storage directory

I need to save the image which was converted using base64 to the storage directory instead of saving it inside the public folder,我需要将使用 base64 转换的图像保存到存储目录而不是将其保存在public中,

Here is my store function which saves the image into my public directory,这是我的商店 function ,它将图像保存到我的public目录中,

public function store(Request $request, Category $category)
{
    if ($request->image) {
        $name = time().'.'. explode('/', explode(':',substr($request->image, 0, strpos($request->image, ';')))[1])[1];

        Image::make($request->image)->save(public_path('img/category/').$name);

    return response('success');
}

I need to know how i can save the images into my storage folder,我需要知道如何将图像保存到我的存储文件夹中,

As described in the Laravel 8 official documentation , on my local laravel installation, I have imported the following:Laravel 8 官方文档中所述,在我本地的 laravel 安装中,我导入了以下内容:

use Illuminate\Support\Facades\Storage;

And then in the store method:然后在 store 方法中:

Storage::disk('local')->put(time() . '.' . 'example.txt', 'Contents');

It stores the file into storage/app and not into the public directory.它将文件存储到 storage/app 中,而不是 public 目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM