laravel框架图片上传

function  add(Da  $req){

$file= $req->file("file"); //接前台值
$tu=$file->getClientOriginalName(); //图片路径
$data=$file->move("image",$tu);
$all= $req->all(); 接收所有的值
$all['file']=$data;

$model=new User();
$res=$model->adddo($all);
if ($res){
return redirect()->route("admin.login")->with("mes","请重新登录");
}

}


//model层
class User extends Author
{
public $table="Users";
public $timestamps=false;
function adddo($data){
$this->name=$data['name'];
$this->email=$data['email'];
$this->password=bcrypt($data['password']);
$this->file=$data['file'];
return $this->save();
}

猜你喜欢

转载自www.cnblogs.com/azzy/p/11748802.html