【问题标题】:Laravel: Storage not putting file inside public folderLaravel:存储未将文件放入公用文件夹
【发布时间】:2018-07-08 20:58:12
【问题描述】:

当我使用时:

Storage::putFile('documents', $content, 'public');

我希望公共目录中的文件夹结构,例如:

+
+-- storage
+--|-- app
+--|--|-- public
+--|--|--|-- documents
+--|--|--|--|-- XyZ.pdf
+

代替:

+
+-- storage
+--|-- app
+--|--|-- documents
+--|--|--|-- XyZ.pdf
+--|--|-- public
+

所以,要强制存储在“正确”的位置,我需要明确放置:

Storage::putFile('public/documents', $content, 'public');

什么返回了我无法保存在数据库中的路径,因为它的值是 "public/documents/xyz.pdf" 并且不能与 asset() 助手一起正常工作。

如何使用Storage门面将文件放入storage/app/public中?

【问题讨论】:

  • Storage::put(public_path('documents'), ... ); ?
  • 你可以试试这里给出的答案:stackoverflow.com/a/44577640/8776138
  • @CyRossignol 不。 public_path() 返回./public 根文件夹的绝对路径

标签: php laravel


【解决方案1】:

这在文档中没有明确说明。

查看config/filesystems.php,我们有一个public 磁盘。就用它吧:

Storage::disk('public')->put('documents', $content);

【讨论】:

  • 啊,我明白你现在想做什么了。顺便说一句,here are the docs.
  • 作为上述的补充,使用 putFileAs() 方法,允许您指定文件名,如果您有一些文件命名约定,这很方便。例如:Storage::disk('public')->putFileAs($location, $file, $fileName, 'public');
  • 遇到了同样的问题。文档是完全错误的。 Laravel 试图让他们的文档保持如此简单和干净,并忽略了这么多用例,这确实是失败了。
猜你喜欢
  • 2020-01-21
  • 2016-12-02
  • 1970-01-01
  • 2016-07-02
  • 2021-09-08
  • 2011-12-02
  • 2015-02-08
  • 2020-09-05
  • 2021-11-02
相关资源
最近更新 更多