/** * 上传图片 * @param $param */ public function upload($mid, $files) { //判斷用戶 if (!($mid = Helper::uint($mid)) || empty($files)) { return array("flag" => 0, "msg" => Core_Error::getError(-1)); } //判斷圖片類型 $ext = strtolower(trim(substr(strrchr($files["icon"]["name"], '.'), 1))); if (!$this->checkext($ext)) { return array("flag" => 0, "msg" => Core_Error::getError(-5)); } //判斷大小 $size = Helper::uint($files['icon']['size']); if (!$this->checksize($size)) { return array("flag" => 0, "msg" => Core_Error::getError(-6)); } //按用戶mid分子目錄 $subname = $mid % 100; if (!is_dir($this->uploadPath)) { mkdir($this->uploadPath); } if (!is_dir($this->uploadPath . "/" . $subname . '/')) { mkdir($this->uploadPath . "/" . $subname . '/'); } $new_name = $this->uploadPath . "/" . $subname . '/' . $mid . '.jpg'; $tmp_name = $files["icon"]["tmp_name"]; if (@copy($tmp_name, $new_name)) { @unlink($tmp_name); } elseif (function_exists('move_uploaded_file') && @move_uploaded_file($tmp_name, $new_name)) { } elseif (@rename($tmp_name, $new_name)) { } else { return array("flag" => 0, "msg" => Core_Error::getError(-7)); } $timebefore = $this->setIconTime($mid, 0); $icon_before_image = $mid . $timebefore . "_icon.jpg"; $middle_before_image = $mid . $timebefore . "_middle.jpg"; $big_before_image = $mid . $timebefore . "_big.jpg"; if ($timebefore > 0) { //@unlink($this->uploadPath . $subname . '/' .$icon_before_image); @unlink($this->uploadPath . $subname . '/' . $middle_before_image); @unlink($this->uploadPath . $subname . '/' . $big_before_image); } //製作縮略圖 $time = time(); $icon_image = $mid . "_icon.jpg"; $middle_image = $mid . "_middle.jpg"; $big_image = $mid . "_big.jpg"; $big_new_image = $this->uploadPath . $subname . '/' . $middle_image; $icon_new_image = $this->uploadPath . $subname . '/' . $icon_image; $this->makethumb($this->uploadPath . '/' . $subname . '/' . $mid . '.jpg', 30, 30, $this->uploadPath . "/" . $subname . '/' . $icon_image); $this->makethumb($this->uploadPath . '/' . $subname . '/' . $mid . '.jpg', 50, 50, $this->uploadPath . "/" . $subname . '/' . $middle_image); $this->makethumb($this->uploadPath . '/' . $subname . '/' . $mid . '.jpg', 100, 100, $this->uploadPath . "/" . $subname . '/' . $big_image); //$time = time(); $info['icon'] = $this->domainUrl . $subname . '/' . $icon_image . '?v=' . $time; $info['middle'] = $this->domainUrl . $subname . '/' . $middle_image . '?v=' . $time; $info['big'] = $this->domainUrl . $subname . '/' . $big_image . '?v=' . $time; $this->setIconTime($mid, 1, $time); /* $cmd = "chmod -R 775 " . $this->uploadPath . $subname; exec($cmd,$text); //同步上传头像到CDN $ret = $this->CurlImg($mid,$big_new_image,$icon_new_image); echo $ret; */ return array("flag" => 1, 'info' => $info); }
$sitemid = $info['sitemid']; $userinfo = Member::factory()->getOneBySiteMid($sitemid, $sid); if (!$userinfo) { //走注册流程 $info = array(); $info['sitemid'] = $sitemid; $info['sid'] = $sid; $info['mnick'] = $param['username'] ? $param['username'] : "******" . $sitemid; $info['sitemid'] = $sitemid; $info['gender'] = 2; $userinfo = Member::factory()->insert($info); $userinfo['isRegister'] = 1; $userinfo['FirstLogin'] = 1; } else { //更新登录信息 if (empty($userinfo['mnick'])) { $userinfo['mnick'] = $param['username']; } Member::factory()->updateLogin($userinfo); $userinfo['isRegister'] = 0; } //判断用户状态 if ($userinfo['status'] == 1) { $ret = array('code' => '-4', 'msg' => Core_Error::getError(-4)); Lib_Mobile::jsonRet($ret, 0); } //格式化userinfo Core_Member::factory()->formatUserInfo($userinfo); //初始化一些设置 $ret = Core_Member::factory()->loadinit($userinfo, $api, $version); Lib_Mobile::jsonRet($ret, 1);