Laravel框架中上传图片

时间:2022-03-07 13:21:55
    public function file(){
    $id=$request->input("id");       //id
    $m_idcard=$request->input("m_idcard");     //图片名称
    $file = $request->file('m_license');
    $hou = $file->getClientOriginalExtension();//文件后缀
    $path = './admin/public/';
    $filename = rand(1, 999999) . "." . $hou;
    $m_license = $path . $filename;     //文件路径
    $file->move($path, $filename);  // 移动文件到指定目录
    $arr=array('m_license'=>$m_license,'m_idcard'=>$m_idcard);
    $re=DB::table('merchant')
        ->where(['id'=>$id] )
        ->update($arr);
    //var_dump($re);die;
    if($re){
        $s=DB::select("select m_phone from merchant where id='$id'");
        return view("mer.login.mermessage",['list'=>$s]);
    }else{
        echo "失败";
    }
    //return redirect('mercarList');
}

相关文章