예제 #1
0
 public function addpictureAction()
 {
     $this->_helper->viewRenderer->setNoRender();
     $this->_helper->getHelper("layout")->disableLayout();
     $this->getFileUploadScript();
     $oUploadHandler = new AppCms2_UploadHandler();
     $oUserParam = new Admin_Model_UserParam();
     if ($this->_request->isPost()) {
         $aResult = $oUploadHandler->post();
         if (!isset($aResult["files"][0]->error)) {
             $aPostData = $this->_request->getPost();
             $nUserId = (int) $aPostData["add_photo_user_id"];
             $nMediaWidth = $aPostData["media_width"];
             $nMediaHeight = $aPostData["media_height"];
             $sUserName = $aResult["files"][0]->name;
             $sGenName = $aResult["files"][0]->gen_name;
             if (!is_dir($this->_sPath . "user_id_" . $nUserId)) {
                 if (!mkdir($this->_sPath . "user_id_" . $nUserId, 0777)) {
                     throw new Zend_Exception();
                 }
             }
             $oImagic = new AppCms2_Imagick($this->_sPath . $sUserName);
             if (isset($nMediaWidth) && isset($nMediaHeight)) {
                 $oImagic->cropimage((int) $nMediaWidth, (int) $nMediaHeight, 0, 0);
             }
             $oImagic->writeImage($this->_sPath . "user_id_" . $nUserId . "/normal_" . $sGenName);
             $oImagic->cropThumbnailImage(70, 100);
             $oImagic->writeImage($this->_sPath . "user_id_" . $nUserId . "/min_" . $sGenName);
             $oImagic->writeImage($this->_sPath . "thumbnail/" . $sGenName);
             unlink($this->_sPath . $sUserName);
             if (file_exists($this->_sPath . $sUserName)) {
                 throw new Zend_Exception();
             }
             $oModelImage = new Admin_Model_Image();
             $nImageId = $oModelImage->saveImage(3, null, $sGenName, $sUserName);
             $oUserParam->editImageUserParam($nUserId, $nImageId);
         } else {
             $sUserName = $aResult["files"][0]->name;
             unlink($this->_sPath . $sUserName);
         }
         $oModelImage->deleteUnused();
     }
     exit;
 }