我正在将文件上传到我的系统中,在本地使用 Windows 和 XAMPP 时可以正常工作,但在托管在 Ubuntu 栈上时,我的文件无法上传。我收到一个错误消息,说它不能写入位于公共文件夹内的 'system' 目录。这是我的代码:
$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();
在寻找解决方案之后,我发现我应该使我的目录可写,因此我在Putty中运行了以下命令:
chmod 770 /var/www/html/public/system
但是即使这样,我仍然遇到了一个错误:无法写入“/var/www/html/public/system”目录
。
我使用的是Laravel 5,我的主机是Digital Ocean。谢谢。
chmod 755 /var/www/html/public/system
和chown www-data:www-data /var/www/html/public/system
。这将更改系统权限和所有者。 - codegenin