【发布时间】:2017-12-18 22:15:24
【问题描述】:
我一直在尝试将文件存储到(并从中获取)storage/app/,跟随the doc。
运行php artisan storage:link后,我可以看到有一个指向公共文件夹的链接。
如果我放一个包含以下代码的文件...
Storage::put('/images/blah.png', $file);
...存储将如下所示。
我不确定链接是否正常工作,因为无法检索此 blah.png。
到目前为止,我已将storage 的访问级别更改为chmod -R 755 storage/,并输入了完整的URL(http://localhost:8000/storage/images/blah.png。这是asset('storage/images/blah.png') 返回的内容)。不过,我收到 404 错误(未找到)。
在config/filessystems.php。默认设置为local。 (即'default' => 'local')
你看到我做错了什么吗?
我们将不胜感激。
附言
公盘的配置是这样的……
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL') . '/storage',
'visibility' => 'public',
],
//env('APP_URL').'/storage' returns 'root/storage/app/public'
【问题讨论】:
-
storage在public目录之外,因此无法通过网络访问。 -
@fubar 这就是
php artisan storage:link的意义所在,它将public/storage中的符号链接指向storage/app/public。 -
@ceejayoz - 我不知道它存在。然而,不管这一点,OP 将文件存储在
storage/app/images,而不是storage/app/public,因此它仍然无法从网络访问。 -
@fubar 很好。这几乎肯定是问题所在!
-
谢谢@fubar 和@ceejayoz。
Storage::put('file name', $file)不会在storage/app/public下保存文件。我觉得链接本身没有按预期工作。