我正在我的系统中上传文件,它在本地工作,我使用的是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
但即使在此之后我仍然收到错误Unable to write in the "/var/www/html/public/system" directory
。
我正在使用laravel 5而我的主机是数字海洋。感谢
答案 0 :(得分:23)
chmod 755 /var/www/html/public/system
和chown www-data:www-data /var/www/html/public/system
效果很好。非常感谢你们。
答案 1 :(得分:1)
文件夹 sudo chmod 777./(folder name)
用于文件 sudo chmod 777 -R ./(file name)
答案 2 :(得分:0)
每当必须创建目录时,请使用以下命令:
use File;
use Illuminate\Foundation\Bus\DispatchesJobs;
在控制器中使用此
if (!file_exists(public_path().'system')) {
if(File::makeDirectory(public_path().'system',0777,true)){
}
}
在您的函数中使用此