【问题标题】:Laravel file storage link not found exceptionLaravel 文件存储链接未找到异常
【发布时间】:2017-07-27 21:26:51
【问题描述】:

使用 Laravel 5.4。它给了我一个错误

RouteCollection.php 第 161 行中的 NotFoundHttpException:

我正在上传存储目录下的文件。我可以看到project-root/storage/app/files中的文件

我还使用php artisan storage:link 创建了符号链接。当我访问生成的链接 (http://example.com/storage/files/RcDPA5N6FpTWCnnh2w8bQO85id53oAiCeZgITpwB.png) 但是,它给了我未找到的异常。

我还想知道我是否指的是资源,那么为什么要调用路由。

【问题讨论】:

  • 报错告诉你找不到路由。意味着 laravel 试图从你的 routes.php 文件中获取路由。尝试使用文件名作为变量注册路由并尝试在控制器中访问它。

标签: php laravel file routes laravel-5.4


【解决方案1】:

该命令将生成指向app/storage/public 的符号链接,因此文件需要进入app/storage/public/files,然后它们应该可以通过http://example.com/storage/files/RcDPA5N6FpTWCnnh2w8bQO85id53oAiCeZgITpwB.png 访问。

【讨论】:

  • php artisan storage:link 在名为 storage 的公共目录中创建一个文件夹链接。这应该是可访问的。像 /js/app.js 一样可以访问 storage/file.jpg 也应该可以访问!!!
  • 根据文档和本地测试,我认为您的files 文件夹应该在storage/app/public 中。
  • 根据你的最后评论,我认为我使用的是 `$path = $file->store('files');` 而我应该使用 `$path = $file->store('public ');` 感谢图片现在可以正常工作了
猜你喜欢
  • 1970-01-01
  • 2021-02-12
  • 1970-01-01
  • 2017-09-19
  • 2022-01-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-11
相关资源
最近更新 更多