예제 #1
0
파일: Avatar.php 프로젝트: monarcmoso/beta2
 public function saveAvatarFile()
 {
     $uploadedFile = null;
     if ($fileData = $this->getAvatarFileData()) {
         $uploader = new Varien_File_Uploader($this->getAvatarFileData());
         $uploader->setFilesDispersion(true);
         $uploader->setFilenamesCaseSensitivity(false);
         $uploader->setAllowRenameFiles(true);
         $uploader->setAllowedExtensions($this->_supportedExtensions);
         $uploader->save($this->getAvatarBasePath(), $fileData['name']);
         $uploadedFile = $uploader->getUploadedFileName();
     }
     return $uploadedFile;
 }
예제 #2
0
 /**
  * Export attribute value to entity model
  *
  * @param Mage_Core_Model_Abstract $entity
  * @param array|string $value
  * @return Mage_Eav_Model_Attribute_Data_File
  */
 public function compactValue($value)
 {
     if ($this->getIsAjaxRequest()) {
         return $this;
     }
     $attribute = $this->getAttribute();
     $original = $this->getEntity()->getData($attribute->getAttributeCode());
     $toDelete = false;
     if ($original) {
         if (!$attribute->getIsRequired() && !empty($value['delete'])) {
             $toDelete = true;
         }
         if (!empty($value['tmp_name'])) {
             $toDelete = true;
         }
     }
     $path = Mage::getBaseDir('media') . DS . $attribute->getEntity()->getEntityTypeCode();
     // unlink entity file
     if ($toDelete) {
         $this->getEntity()->setData($attribute->getAttributeCode(), '');
         $file = $path . $original;
         $ioFile = new Varien_Io_File();
         if ($ioFile->fileExists($file)) {
             $ioFile->rm($file);
         }
     }
     if (!empty($value['tmp_name'])) {
         try {
             $uploader = new Varien_File_Uploader($value);
             $uploader->setFilesDispersion(true);
             $uploader->setFilenamesCaseSensitivity(false);
             $uploader->setAllowRenameFiles(true);
             $uploader->save($path, $value['name']);
             $fileName = $uploader->getUploadedFileName();
             $this->getEntity()->setData($attribute->getAttributeCode(), $fileName);
         } catch (Exception $e) {
             Mage::logException($e);
         }
     }
     return $this;
 }
예제 #3
0
 public function saveAction()
 {
     $post_data = $this->getRequest()->getPost();
     if ($post_data) {
         try {
             $path = Mage::getBaseDir('media') . DS . 'cdz' . DS . 'revslideshow' . DS . 'images';
             foreach ($_FILES as $key => $value) {
                 $temp = explode("_", $key);
                 if (!empty($value['tmp_name'])) {
                     try {
                         $uploader = new Varien_File_Uploader($value);
                         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                         $uploader->setFilesDispersion(false);
                         $uploader->setFilenamesCaseSensitivity(false);
                         $uploader->setAllowRenameFiles(true);
                         $imageName = Mage::helper('revslideshow')->replaceFileName($value['name']);
                         $uploader->save($path, $imageName);
                         $fileName = $uploader->getUploadedFileName();
                         $post_data['slider'][$temp[1]]['image'] = $fileName;
                     } catch (Exception $e) {
                         Mage::logException($e);
                         Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
                     }
                 }
             }
             foreach ($post_data['slider'] as $key => $value) {
                 if (!$post_data['slider'][$key]['image']) {
                     $post_data['slider'][$key]['image'] = $value[$key]['image'];
                 }
             }
             $model = Mage::getModel("revslideshow/revslideshow");
             if (isset($post_data["duplicate"])) {
                 $model->setId();
             } else {
                 $model->setId($this->getRequest()->getParam("id"));
             }
             $post_data['general_settings'] = json_encode($post_data['general_settings'], JSON_HEX_TAG);
             $post_data['appearance'] = json_encode($post_data['appearance'], JSON_HEX_TAG);
             $post_data['loop'] = json_encode($post_data['loop'], JSON_HEX_TAG);
             $post_data['mobile_settings'] = json_encode($post_data['mobile_settings'], JSON_HEX_TAG);
             $post_data['navigation'] = json_encode($post_data['navigation'], JSON_HEX_TAG);
             $post_data['parallax'] = json_encode($post_data['parallax'], JSON_HEX_TAG);
             $post_data['spinner'] = json_encode($post_data['spinner'], JSON_HEX_TAG);
             $post_data['slider'] = json_encode($post_data['slider'], JSON_HEX_TAG);
             $post_data['thumbnails'] = json_encode($post_data['thumbnails'], JSON_HEX_TAG);
             $model->addData($post_data);
             $model->save();
             Mage::getSingleton("adminhtml/session")->addSuccess(Mage::helper("adminhtml")->__("Revslideshow was successfully saved"));
             Mage::getSingleton("adminhtml/session")->setRevslideshowData(false);
             if ($this->getRequest()->getParam("back")) {
                 $this->_redirect("*/*/edit", array("id" => $model->getId()));
                 return;
             }
             $this->_redirect("*/*/");
             return;
         } catch (Exception $e) {
             Mage::getSingleton("adminhtml/session")->addError($e->getMessage());
             Mage::getSingleton("adminhtml/session")->setRevslideshowData($this->getRequest()->getPost());
             $this->_redirect("*/*/edit", array("id" => $this->getRequest()->getParam("id")));
             return;
         }
     }
     $this->_redirect("*/*/");
 }