Laravel上传文件无法写入目录 [英] Laravel uploading file Unable to write in directory
问题描述
我正在系统中上载文件,它在使用Windows和Xampp的本地工作,但是在使用Ubuntu堆栈的地方托管时,我的文件未上载.我收到一个错误消息,它不能写在公用文件夹内的系统"目录中.这是我的代码
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
$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
chmod 770/var/www/html/public/system
但即使在此之后仍然出现错误无法在"/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
.
我正在使用laravel 5,我的主人是数字海洋.谢谢
I'm using laravel 5 and my host is digital ocean. Thanks
推荐答案
chmod 755/var/www/html/public/system
和 chown www-data:www-data/var@JLPuro所述的/www/html/public/system
效果很好.非常感谢.
chmod 755 /var/www/html/public/system
and chown www-data:www-data /var/www/html/public/system
as stated by @JLPuro works perfectly. Thanks a lot guys.
这篇关于Laravel上传文件无法写入目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!