我正在我的系统中上传文件,它在本地使用 Windows 和 xampp,但在使用 Ubuntu 堆栈的地方托管时,我的文件没有被上传。我收到一个错误,它不能写入公共(public)文件夹内的“系统”目录。这是我的代码
$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
但即使在那之后我仍然收到错误 Unable to write in the "/var/www/html/public/system"directory
。
我使用的是 laravel 5,我的主机是 digital ocean。谢谢
最佳答案
chmod 755/var/www/html/public/system
和 chown www-data:www-data/var/www/html/public/system
如前所述@JLPuro 的作品完美无缺。非常感谢大家。
关于php - Laravel上传文件无法写入目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34836602/