【问题标题】:How to save image in laravel storage directory如何将图像保存在laravel存储目录中
【发布时间】:2021-01-22 03:10:08
【问题描述】:

我需要将使用base64转换的图像保存到存储目录,而不是将其保存在public文件夹中,

这是我的存储功能,它将图像保存到我的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');
}

我需要知道如何将图像保存到我的存储文件夹中,

【问题讨论】:

  • 你运行了 php artisan storage:link 吗?
  • @TariqImtinan 是的,我做了,我需要知道如何编写将数据保存到存储目录的函数,上面的代码将文件保存到 public/img/category 目录

标签: php laravel base64 laravel-7 intervention


【解决方案1】:

Laravel 8 official documentation 中所述,在我的本地 laravel 安装中,我已导入以下内容:

use Illuminate\Support\Facades\Storage;

然后在store方法中:

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

它将文件存储到 storage/app 而不是公共目录。

【讨论】:

    猜你喜欢
    • 2018-09-27
    • 2021-06-02
    • 1970-01-01
    • 2011-11-13
    • 1970-01-01
    • 2019-09-07
    • 2021-05-24
    • 1970-01-01
    • 2012-08-13
    相关资源
    最近更新 更多