php Laravel 上传文件无法写入目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34836602/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:14:44  来源:igfitidea点击:

Laravel uploading file Unable to write in directory

phplaravelfile-uploadlaravel-5digital-ocean

提问by user3714932

I'm uploading files in my system and it works locally where am using windows and xampp but when hosting where am using an Ubuntu stack my file is not being uploaded. I'm getting an error that it cannot be written in the 'system' directory which is within the public folder. This is my code

我正在我的系统中上传文件,它在使用 windows 和 xampp 的本地工作,但是在使用 Ubuntu 堆栈的地方托管时,我的文件没有被上传。我收到一个错误,提示它无法写入公共文件夹内的“系统”目录。这是我的代码

 $destinationPath = public_path().'/system'; // upload path
  $extension = Request::file('add_students')->getClientOriginalExtension(); // getting excel extension
  // dd($extension);
  $fileName = rand(11111,99999).'.'.$extension; // renameing excel file
  $file=Request::file('add_students')->move($destinationPath, $fileName); // uploading file to given path
  $path=$file->getRealPath();

after looking for solutions I found out that I should make my directory writable so I ran the following command in putty

在寻找解决方案后,我发现我应该使我的目录可写,所以我在 putty 中运行了以下命令

chmod 770 /var/www/html/public/system

chmod 770 /var/www/html/public/system

but still even after that am getting an error Unable to write in the "/var/www/html/public/system" directory.

但即使在那之后我仍然收到错误Unable to write in the "/var/www/html/public/system" directory

I'm using laravel 5 and my host is digital ocean. Thanks

我正在使用 laravel 5,我的主机是数字海洋。谢谢

回答by user3714932

chmod 755 /var/www/html/public/systemand chown www-data:www-data /var/www/html/public/systemas stated by @JLPuro works perfectly. Thanks a lot guys.

chmod 755 /var/www/html/public/systemchown www-data:www-data /var/www/html/public/system通过@JLPuro说完美的作品。非常感谢各位。

回答by Jyotirmoy Bhattacharjee

permission for foldersudo chmod 777./(folder name)

文件夹权限sudo chmod 777./(folder name)

for filesudo chmod 777 -R ./(file name)

对于文件sudo chmod 777 -R ./(file name)