예제 #1
0
 public function userUploadPhotoAction()
 {
     $check_auth = new CheckAuthorization($this->getQemyDb());
     $check_auth->check();
     $user = new User($this->getQemyDb(), $check_auth->getUserRow());
     $user->setAuthChecker($check_auth);
     if (!$user->isAuth()) {
         Application::denied();
         $this->setData(array('result' => false));
         return $this;
     }
     $file_name = date("mdy") . '_' . sha1($user->getId() . $user->getEmail() . time() . rand(1, 1000000000.0));
     $storage_host = Application::$config['user_files_opt']['host'];
     $image_url = Application::$config['user_files_opt']['protocol'] . '://' . $storage_host . '/img/profile/' . $file_name . '.png';
     try {
         $mWideImage = WideImage::loadFromUpload('image');
         $resizedImage = $mWideImage->resize(200, 200, 'outside', 'down')->crop('center', 'center', 200, 200);
         $resizedImage->saveToFile('../' . $storage_host . '/img/profile/' . $file_name . '.png');
         $user->setPhoto($image_url);
         $result = true;
     } catch (WideImage_Exception $err) {
         $result = false;
     }
     $this->setData(array('result' => $result));
     return $this;
 }