public function modify_icon() { $this->act_data['modify_icon']['desc'] = "修改头像"; //获取上传文件信息; $file = request()->file('file'); $filePaths = ROOT_PATH . 'public' . DS . 'uploads'; if (!file_exists($filePaths)) { mkdir($filePaths, 0777); } //单张图片上传 $info = $file->move($filePaths); if (empty($info)) { $e = new user_exception(); $e->seterror(843); throw $e; } $imgpath = ROOT_PATH . 'public' . DS . 'uploads/' . $info->getSaveName(); //图片上传阿里云 $dir = "person/head/" . date('y-m-d', time()); $path = toolapp::toolOss($dir, $imgpath); if ($path['status'] == 1) { unset($info);//清除文件,非常重要; //插入数据库; Db::name(self::model_user)->where("f_user_id", $this->userinfo['f_user_id'])->update([ 'f_user_headicon' => $path['url'] ]); //清除本地文件 toolapp::del_dir($filePaths); Session::set("userinfo.f_user_headicon",toolapp::imgurl_aliyun($path['url'])); //返回数据; return [ 'msg' => '上传成功!', 'url' => toolapp::imgurl_aliyun($path['url']) ]; }else{ $e = new user_exception(); $e->seterror(607); throw $e; } }
tp 单张图片上传处理
猜你喜欢
转载自www.cnblogs.com/wangfenphph2/p/9213987.html
今日推荐
周排行