Laravel 无法创建根目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48013965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Impossible to Create Root Directory
提问by Zach Handley
I've checked out the other posts about this, mine seems to be unique for some reason
我已经查看了关于此的其他帖子,由于某种原因,我的似乎是独一无二的
Essentially what I'm trying to do is store uploaded photos in the public directory for easy access, however when I store them I'm trying to store them in a user specific folder, so
基本上我想要做的是将上传的照片存储在公共目录中以便于访问,但是当我存储它们时我试图将它们存储在用户特定的文件夹中,所以
/public/photos/$User->id/$filename.jpg
Right now I have Dropzone uploading the file, and I've added to my filesystem.php this statement
现在我有 Dropzone 上传文件,我已经在我的 filesystem.php 中添加了这个语句
'public_uploads' => [
'driver' => 'local',
'root' => public_path(),
],
So in theory when I access that using
所以理论上当我使用
Storage::disk('public_uploads')
it should retrieve the correct path
它应该检索正确的路径
Here's my controller as well
这也是我的控制器
$User = User::find(Auth::user()->id);
$Photo = Request::file('photo');
Storage::disk('public_uploads')->put("photos/$User->id", $Photo);
Then I get this error from Laravel on upload
然后我在上传时从 Laravel 收到此错误
{message: "Impossible to create the root directory "/censoredfilesystem/public/Photos/1".",…}
No idea where the period is coming from and any help is greatly appreciated
不知道这个时期是从哪里来的,非常感谢任何帮助
Thanks all!
谢谢大家!
- Zach
- 扎克
采纳答案by Zach Handley
Fixed it unknowningly by setting permissions according to comments, I used
根据评论设置权限不知不觉地修复了它,我用过
chown -R www-data:root .
in the root of my directory
在我的目录的根目录中
Edit: I used www-data:root
, meaning set the owner of everything inside the Laravel directory to www-data
(the webserver) and root
being root
obviously. If you do this you should do it with a non-root user or just to www-data
编辑:我使用www-data:root
,这意味着一套Laravel目录内一切的所有者www-data
(Web服务器),并root
为root
明显。如果你这样做,你应该用非 root 用户来做,或者只是为了www-data
回答by bravohex
In Centos and nginx:
在 Centos 和 nginx 中:
sudo chown -R nginx:root public/duck/