【问题标题】:how to upload image to public folder not to storage?如何将图像上传到公共文件夹而不是存储?
【发布时间】:2019-12-29 18:57:50
【问题描述】:

我想将图像上传到 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 中

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

【问题讨论】:

  • 你有什么特别的原因要使用公用文件夹吗?

标签: laravel laravel-5 laravel-5.8


【解决方案1】:

在 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-22
    • 2016-07-02
    • 2018-07-16
    • 2018-03-24
    • 2021-11-03
    • 2020-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多