首页 > 解决方案 > 如何将图像上传到公共文件夹而不是存储?

问题描述

我想将图像上传到 imgs 文件夹内的公用文件夹,所以我尝试将以下内容添加到 cofig/filesystems.php:

'pub' => [
            'driver' => 'local',
            'root'   => '/imgs',
            'url' => env('APP_URL').'/public',
            'visibility' => 'public',
        ] 

但现在当我使用$d->storeAs('products', $name.$ext, ['storage' => 'pub']);图像保存在 storage/app/public/imgs/products 而不是 public/imgs/products

我如何将它们存储在公共而不是存储中?

标签: laravellaravel-5laravel-5.8

解决方案


在 Laravel 5 中,您现在必须在 config/filesystems.php 中执行此操作。

您可以像这样添加新磁盘:

'disks' => [
  'uploads' => [
      'driver' => 'local',
      'root'   => public_path(), // previously storage_path();
   ],
]

然后执行以下操作来使用它:

Storage::disk('uploads')->put('filename', $file_content);

参考 :

https://laracasts.com/discuss/channels/laravel/change-the-storage-path-to-public-laravel-53


推荐阅读