예제 #1
0
 protected function _afterSave()
 {
     if ($this->getFrmImageUrl()) {
         if (isset($_FILES['upload_image']['error']) && UPLOAD_ERR_OK == $_FILES['upload_image']['error']) {
             try {
                 // trying to upload image
                 $uploader = new Varien_File_Uploader('upload_image');
                 $uploader->setFilesDispersion(false);
                 $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                 $uploader->save(Mage::helper('amfeed')->getDownloadPath('images'), $this->getId() . '.jpg');
             } catch (Exception $e) {
                 throw new Exception(Mage::helper('amfeed')->__('An error occurred while saving the feed: %s', $e->getMessage()));
             }
             unset($_FILES['upload_image']);
             $this->setDefaultImage(1)->save();
         }
     } else {
         $path = Mage::helper('amfeed')->getDownloadPath('images', $this->getId() . '.jpg');
         if (file_exists($path)) {
             Mage::helper('amfeed')->deleteFile($path);
             $this->setDefaultImage(0)->save();
         }
     }
     return parent::_afterSave();
 }