laravel - 如何将图像上传到公共文件夹而不是存储?
问题描述
我想将图像上传到 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 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
推荐阅读
- php - 显示具有某些条件的数据库字段
- typescript - Angular8 材质,带有标题和瓷砖的网格。mat-grid-tile 内容未完全调整大小
- node.js - 访问安装在 Linux 服务器上的 NodeJS 服务器
- mysql - 谷歌云 SQL 迁移到第二代导致读/写操作激增
- sql - 查询最近日期
- r - 如何应用机器学习技术/如何使用模型输出
- python - Python 从一个运行多个脚本
- sql - SQL - 具有多个日期的条件窗口
- ios - 将 Gif 从 URL 加载到 CollectionViewCell
- python - 如何从 seaborn 的 KDE distplot 对象中提取 bin?