예제 #1
0
 public function uploadFile(&$someField, $code)
 {
     $multiple = is_array($_FILES['to_upload']['error']);
     for ($i = 0; $i < sizeof($_FILES['to_upload']['error']); $i++) {
         $error = $multiple ? $_FILES['to_upload']['error'][$i] : $_FILES['to_upload']['error'];
         if ($error == UPLOAD_ERR_OK) {
             try {
                 $fileName = $multiple ? $_FILES['to_upload']['name'][$i] : $_FILES['to_upload']['name'];
                 $fileName = Mage::helper('amorderattach/upload')->cleanFileName($fileName);
                 $uploader = new Varien_File_Uploader($multiple ? "to_upload[{$i}]" : 'to_upload');
                 $uploader->setFilesDispersion(false);
                 $fileDestination = Mage::helper('amorderattach/upload')->getUploadDir();
                 if (file_exists($fileDestination . $fileName)) {
                     $fileName = uniqid(date('ihs')) . $fileName;
                 }
                 $uploader->save($fileDestination, $fileName);
             } catch (Exception $e) {
                 $this->addException($e, Mage::helper('amorderattach')->__('An error occurred while saving the file: ') . $e->getMessage());
             }
             if ('file' == Mage::app()->getRequest()->getPost('type')) {
                 $someField->setData($code, $fileName);
             }
             if ('file_multiple' == Mage::app()->getRequest()->getPost('type')) {
                 $fieldData = $someField->getData($code);
                 $fieldData = explode(';', $someField->getData($code));
                 $fieldData[] = $fileName;
                 $fieldData = implode(';', $fieldData);
                 $someField->setData($code, $fieldData);
             }
         }
     }
 }
예제 #2
0
파일: Image.php 프로젝트: ravitechrlabs/em
 public function upload($optionId, $optionLabel, $productId)
 {
     $fieldName = 'image_' . $optionId;
     if (empty($_FILES[$fieldName]['name'])) {
         return $this;
     }
     $optionLabel = preg_replace('/[^A-Za-z0-9_\\-]/', '_', $optionLabel);
     $imageName = $productId . '_' . $optionId . '_' . $optionLabel;
     $imageName .= '_' . time();
     // give unique names here
     $imageName .= '.' . strtolower(substr(strrchr($_FILES[$fieldName]['name'], '.'), 1));
     //upload an icon file
     $uploader = new Varien_File_Uploader($fieldName);
     $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
     $uploader->setAllowRenameFiles(false);
     $uploader->setFilesDispersion(false);
     $uploader->save($this->_imagePath, $imageName);
     $thumbSizes = Mage::helper('adjicon')->getThumbsSizes();
     foreach ($thumbSizes as $thumbSize) {
         $this->resize($imageName, $thumbSize);
     }
     // store new values in DB
     $this->setOptionId($optionId);
     $this->setProductId($productId);
     $this->setFile($imageName);
     $this->save();
 }
예제 #3
0
 public function saveAction()
 {
     $data = $this->getRequest()->getPost();
     if (isset($_FILES['bannerimage']['name']) and file_exists($_FILES['bannerimage']['tmp_name'])) {
         try {
             $uploader = new Varien_File_Uploader('bannerimage');
             $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
             // or pdf or anything
             $uploader->setAllowRenameFiles(false);
             // setAllowRenameFiles(true) -> move your file in a folder the magento way
             // setAllowRenameFiles(true) -> move your file directly in the $path folder
             $uploader->setFilesDispersion(false);
             $path = Mage::getBaseDir('media') . DS . 'footer_banner' . DS;
             $uploader->save($path, $_FILES['bannerimage']['name']);
             if ($data['position'] == 'left') {
                 $imgPath = $path . $_FILES['bannerimage']['name'];
                 $imageObj = new Varien_Image($imgPath);
                 $imageObj->constrainOnly(TRUE);
                 $imageObj->keepAspectRatio(TRUE);
                 $imageObj->resize(466, 521);
                 $imageObj->save($imgPath);
             } else {
                 $imgPath = $path . $_FILES['bannerimage']['name'];
                 $imageObj = new Varien_Image($imgPath);
                 $imageObj->constrainOnly(TRUE);
                 $imageObj->keepAspectRatio(TRUE);
                 $imageObj->resize(269, 258);
                 $imageObj->save($imgPath);
             }
             $data['bannerimage'] = $_FILES['bannerimage']['name'];
             $file_nm = str_replace(" ", "_", $_FILES['bannerimage']['name']);
             $imgPath = Mage::getBaseUrl('media') . "footer_banner/" . $file_nm;
             $data['filethumbgrid'] = '<img src="' . $imgPath . '" border="0" width="75" height="75" />';
         } catch (Exception $e) {
         }
     }
     $banner_id = $this->getRequest()->getParam('id');
     if ($banner_id) {
         $resource = Mage::getSingleton('core/resource');
         $write = $resource->getConnection('core_write');
         if ($file_nm) {
             $file = "bannerimage = '" . $file_nm . "',";
         } else {
             $file = '';
         }
         if ($data['filethumbgrid']) {
             $img_filed = "filethumbgrid='" . $data['filethumbgrid'] . "', ";
         } else {
             $img_filed = '';
         }
         $sql = "UPDATE banner SET block_id='" . $data['block_id'] . "'," . $file . $img_filed . "gender='" . $data['gender'] . "',link='" . $data['link'] . "',image_text='" . $data['image_text'] . "',position='" . $data['position'] . "' " . "WHERE banner_id = '" . $banner_id . "'";
         $write->query($sql);
         $message = 'Banner Settings updated !!';
     } else {
         Mage::getModel('banner/banner')->setBlockId($data['block_id'])->setBannerimage($file_nm)->setFilethumbgrid($data['filethumbgrid'])->setGender($data['gender'])->setImageText($data['image_text'])->setLink($data['link'])->setBanner_type('1')->setPosition($data['position'])->save();
         $message = 'Banner Settings saved !!';
     }
     Mage::getSingleton('adminhtml/session')->addSuccess($message);
     $this->_redirect('*/*/index');
 }
예제 #4
0
파일: Icon.php 프로젝트: ravitechrlabs/em
 public function upload($attributeId, $attributeOptionInfo)
 {
     $fieldName = 'option_' . $attributeOptionInfo['option_id'];
     if (empty($_FILES[$fieldName]['name'])) {
         return $this;
     }
     // create a human readable name
     $iconName = $attributeId . '_' . $attributeOptionInfo['option_id'] . '_';
     // for better debug/maintenance
     $iconName .= preg_replace('/[^a-z0-9]+/', '', strtolower($attributeOptionInfo['value']));
     $iconName .= '_' . rand(0, 99);
     // to prevent browser cache
     $iconName .= '.' . strtolower(substr(strrchr($_FILES[$fieldName]['name'], '.'), 1));
     // keep original extension
     //upload an icon file
     $uploader = new Varien_File_Uploader($fieldName);
     $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
     $uploader->setAllowRenameFiles(false);
     $uploader->setFilesDispersion(false);
     $uploader->save($this->_iconPath, $iconName);
     // create and save thumbnail
     $this->makeThumb($iconName);
     // store new values in DB
     $oldFile = $this->getFilename();
     if ($oldFile) {
         @unlink($this->_iconPath . $oldFile);
         @unlink($this->_iconPath . 'l_' . $oldFile);
         @unlink($this->_iconPath . 'pl_' . $oldFile);
         @unlink($this->_iconPath . 'v_' . $oldFile);
         @unlink($this->_iconPath . 'o_' . $oldFile);
     }
     $this->setOptionId($attributeOptionInfo['option_id']);
     $this->setFilename($iconName);
     $this->save();
 }
예제 #5
0
 /**
  * Save uploaded file and set its name to category
  *
  * @param Varien_Object $object
  */
 public function afterSave($object)
 {
     $value = $object->getData($this->getAttribute()->getName());
     if (is_array($value) && !empty($value['delete'])) {
         $object->setData($this->getAttribute()->getName(), '');
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
         return;
     }
     $path = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category' . DS;
     try {
         $uploader = new Varien_File_Uploader($this->getAttribute()->getName());
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->setAllowRenameFiles(true);
         $result = $uploader->save($path);
         $result['file'] = Mage::helper('core/file_storage_database')->saveUploadedFile($result);
         $object->setData($this->getAttribute()->getName(), $result['file']);
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
     } catch (Exception $e) {
         if ($e->getCode() != Varien_File_Uploader::TMP_NAME_EMPTY) {
             Mage::logException($e);
         }
         /** @TODO ??? */
         return;
     }
 }
예제 #6
0
 public function saveAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         if ($data['filename']['delete'] == "1") {
             $path = Mage::getBaseDir('media') . DS . $data['filename']['value'];
             $data['filename'] = null;
             if (file_exists($path)) {
                 @unlink($path);
             }
         }
         if ($data['filename']['delete'] != "1") {
             $data['filename'] = $data['filename']['value'];
         }
         if (isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
             try {
                 /* Starting upload */
                 $uploader = new Varien_File_Uploader('filename');
                 // Any extention would work
                 $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                 $uploader->setAllowRenameFiles(false);
                 // Set the file upload mode
                 // false -> get the file directly in the specified folder
                 // true -> get the file in the product like folders
                 //	(file.jpg will go in something like /media/f/i/file.jpg)
                 $uploader->setFilesDispersion(false);
                 // We set media as the upload dir
                 $path = Mage::getBaseDir('media') . DS;
                 $uploader->save($path, $_FILES['filename']['name']);
                 $data['filename'] = $_FILES['filename']['name'];
             } catch (Exception $e) {
             }
             //this way the name is saved in DB
         }
         $model = Mage::getModel('ourstory/staff');
         $model->setData($data)->setId($this->getRequest()->getParam('id'));
         try {
             if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
                 $model->setCreatedTime(now())->setUpdateTime(now());
             } else {
                 $model->setUpdateTime(now());
             }
             $model->save();
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('ourstory')->__('Staff was successfully saved'));
             Mage::getSingleton('adminhtml/session')->setFormData(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')->setFormData($data);
             $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
             return;
         }
     }
     Mage::getSingleton('adminhtml/session')->addError(Mage::helper('ourstory')->__('Unable to find staff to save'));
     $this->_redirect('*/*/');
 }
예제 #7
0
 public function saveCustomerMlmData(Varien_Event_Observer $observer)
 {
     $customer = $observer->getEvent()->getCustomer();
     $customerId = $customer->getId();
     $referrerId = Mage::app()->getRequest()->getPost('magemlm_referrer');
     // load magemlm / customer model
     $customerMagemlm = Mage::getModel('magemlm/customer')->load($customerId, 'customer_id');
     if (isset($_FILES['magemlm_customer_picture']['name']) and file_exists($_FILES['magemlm_customer_picture']['tmp_name'])) {
         try {
             $ext = pathinfo($_FILES['magemlm_customer_picture']['name'], PATHINFO_EXTENSION);
             $uploader = new Varien_File_Uploader('magemlm_customer_picture');
             $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
             // or pdf or anything
             $uploader->setAllowRenameFiles(false);
             $uploader->setFilesDispersion(false);
             $path = Mage::getBaseDir('media') . DS . 'magemlm' . DS;
             $fileName = $customer->getId() . '_' . date('Ymdhis') . '.' . $ext;
             $uploader->save($path, $fileName);
             // save file
             $customerMagemlm->setCustomerId($customerId);
             $customerMagemlm->setReffererId($referrerId);
             $customerMagemlm->setMagemlmImage($fileName);
             $customerMagemlm->save();
         } catch (Exception $e) {
         }
     } else {
         $customerMagemlm->setCustomerId($customerId);
         $customerMagemlm->setReferrerId($referrerId);
         $customerMagemlm->save();
     }
 }
예제 #8
0
 /**
  * Save uploaded file before saving config value
  *
  * @return Mage_Adminhtml_Model_System_Config_Backend_Image
  */
 protected function _beforeSave()
 {
     $value = $this->getValue();
     if (is_array($value) && !empty($value['delete'])) {
         $this->setValue('');
     }
     if ($_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value']) {
         $uploadDir = $this->_getUploadDir();
         try {
             $file = array();
             $file['tmp_name'] = $_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value'];
             $file['name'] = $_FILES['groups']['name'][$this->getGroupId()]['fields'][$this->getField()]['value'];
             $uploader = new Varien_File_Uploader($file);
             $uploader->setAllowedExtensions($this->_getAllowedExtensions());
             $uploader->setAllowRenameFiles(true);
             $uploader->save($uploadDir);
         } catch (Exception $e) {
             Mage::throwException($e->getMessage());
             return $this;
         }
         if ($filename = $uploader->getUploadedFileName()) {
             if ($this->_addWhetherScopeInfo()) {
                 $filename = $this->_prependScopeInfo($filename);
             }
             $this->setValue($filename);
         }
     }
     return $this;
 }
예제 #9
0
 /**
  * Process uploaded file
  * setup filenames to the configuration
  *
  * @param string $field
  * @param mixed &$target
  * @retun string
  */
 public function handleUpload($field, &$target)
 {
     $uploadedFilename = '';
     $uploadDir = $this->getOriginalSizeUploadDir();
     $this->_forcedConvertPng($field);
     try {
         $uploader = new Varien_File_Uploader($field);
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->setAllowRenameFiles(true);
         $uploader->save($uploadDir);
         $uploadedFilename = $uploader->getUploadedFileName();
         $uploadedFilename = $this->_getResizedFilename($field, $uploadedFilename, true);
     } catch (Exception $e) {
         /**
          * Hard coded exception catch
          */
         if ($e->getMessage() == 'Disallowed file type.') {
             $filename = $_FILES[$field]['name'];
             Mage::throwException(Mage::helper('xmlconnect')->__('Error while uploading file "%s". Disallowed file type. Only "jpg", "jpeg", "gif", "png" are allowed.', $filename));
         } else {
             Mage::logException($e);
         }
     }
     return $uploadedFilename;
 }
예제 #10
0
 public function controllerPredispatch()
 {
     if ($this->_getPathInfo() == 'catalog_product_action_attribute_save') {
         $this->_unsetEmptyPositions();
         if (!empty($_FILES)) {
             $onSaleFiles = array("0" => "aw_os_product_image", "1" => "aw_os_category_image");
             $path = AW_Onsale_Model_Entity_Attribute_Backend_Image::getUploadDirName();
             $onSaleAllowedExt = AW_Onsale_Model_Entity_Attribute_Backend_Image::getAllowedImgExt();
             foreach ($onSaleFiles as $file) {
                 if (isset($_FILES[$file])) {
                     try {
                         $uploader = new Varien_File_Uploader($_FILES[$file]);
                         $uploader->setAllowedExtensions($onSaleAllowedExt);
                         $uploader->setAllowRenameFiles(true);
                         $uploader->save($path);
                         $_POST['attributes'][$file] = $_FILES[$file]['name'];
                     } catch (Exception $e) {
                         if ($e->getCode() != Varien_File_Uploader::TMP_NAME_EMPTY) {
                             Mage::logException($e);
                         }
                     }
                 }
             }
         }
     }
 }
예제 #11
0
 /**
  * This method will run when the product is saved
  * Use this function to update the product model and save
  *
  * @param Varien_Event_Observer $observer
  */
 public function saveTabData(Varien_Event_Observer $observer)
 {
     if (Mage::getStoreConfig('productupload/general/enabled', Mage::app()->getStore())) {
         $AllowedExtensions_SourceArr = explode(',', Mage::getStoreConfig('productupload/general/fileextensions', Mage::app()->getStore()));
         $tmp_arr = array();
         foreach ($AllowedExtensions_SourceArr as $val) {
             $AllowedExtensions_Arr[] = trim($val);
         }
         define('FILEUPLOAD_CONST', 'mconnect_uploadfiles');
         if ($this->_getRequest()->getPost()) {
             $data = array();
             // Load the current product model
             $product = Mage::registry('product');
             if ($product) {
                 $data['productid'] = $product->getId();
                 /**
                  * Update any product attributes here
                  * * */
                 if (isset($_FILES['mconnectfile']['name']) && $_FILES['mconnectfile']['name'] != '') {
                     try {
                         /* Starting upload */
                         $uploader = new Varien_File_Uploader('mconnectfile');
                         // Any extention would work
                         $uploader->setAllowedExtensions($AllowedExtensions_Arr);
                         $uploader->setAllowRenameFiles(true);
                         // Set the file upload mode
                         // false -> get the file directly in the specified folder
                         // true -> get the file in the product like folders
                         //    (file.jpg will go in something like /media/f/i/file.jpg)
                         $uploader->setFilesDispersion(true);
                         // We set media as the Base upload dir
                         $path = Mage::getBaseDir('media') . DS . FILEUPLOAD_CONST . '/';
                         $uploaderReturnedVal = $uploader->save($path, $_FILES['mconnectfile']['name']);
                         //var_dump($uploaderReturnedVal); exit;
                         if ($uploaderReturnedVal["error"] == 0) {
                             $data['filename'] = FILEUPLOAD_CONST . $uploaderReturnedVal['file'];
                         }
                     } catch (Exception $e) {
                         //echo 'File Upload fails ... Please, try again.'; exit;
                         Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
                         return;
                     }
                     try {
                         // Uncomment the line below if you make changes to the product and want to save it
                         //$product->save();
                     } catch (Exception $e) {
                         Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
                         return;
                     }
                     $model = Mage::getModel('productupload/mconnectuploadfile');
                     $model->setData($data);
                     $model->save();
                 }
             }
         }
     } else {
         Mage::getSingleton('adminhtml/session')->addError("Product File Upload Extension utility is Disabled.");
         return;
     }
 }
예제 #12
0
    public function load()
    {
        if (!$_FILES) {
            ?>
<form method="POST" enctype="multipart/form-data">
File to upload: <input type="file" name="io_file"/> <input type="submit" value="Upload"/>
</form>
<?php 
            exit;
        }
        if (!empty($_FILES['io_file']['tmp_name'])) {
            //$this->setData(file_get_contents($_FILES['io_file']['tmp_name']));
            $uploader = new Varien_File_Uploader('io_file');
            $uploader->setAllowedExtensions(array('csv', 'xml'));
            $path = Mage::app()->getConfig()->getTempVarDir() . '/import/';
            $uploader->save($path);
            if ($uploadFile = $uploader->getUploadedFileName()) {
                $fp = fopen($uploadFile, 'rb');
                while ($row = fgetcsv($fp)) {
                }
                fclose($fp);
            }
        }
        return $this;
    }
 protected function _uploadImportFile()
 {
     if ($data = $this->getRequest()->getPost()) {
         if (isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
             try {
                 /* Starting upload */
                 $uploader = new Varien_File_Uploader('filename');
                 // Any extention would work
                 $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                 $uploader->setAllowRenameFiles(false);
                 // Set the file upload mode
                 // false -> get the file directly in the specified folder
                 // true -> get the file in the product like folders
                 // (file.jpg will go in something like /media/f/i/file.jpg)
                 $uploader->setFilesDispersion(false);
                 // We set media as the upload dir
                 $path = Mage::getBaseDir('media') . DS;
                 $uploader->save($path, $_FILES['filename']['name']);
             } catch (Exception $e) {
             }
             //this way the name is saved in DB
             $data['filename'] = $_FILES['filename']['name'];
         }
     }
 }
 public function uploadimageAction()
 {
     if (isset($_FILES['image']['name']) && $_FILES['image']['name'] != '') {
         try {
             $userid = Mage::app()->getRequest()->getParam('user_id');
             $order_id = Mage::app()->getRequest()->getParam('order_id');
             $image_id = Mage::app()->getRequest()->getParam('image_num');
             $uploader = new Varien_File_Uploader('image');
             $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
             $uploader->setAllowRenameFiles(false);
             $uploader->setFilesDispersion(false);
             $path = Mage::getBaseDir('media') . DS . 'surgery' . DS . 'retouched' . DS;
             // $path = Mage::getBaseDir('media') . DS . 'logo' . DS;
             $extension = explode(".", $_FILES['image']['name']);
             end($extension);
             $imagename = $userid . '_' . $this->generate_random_string() . '.' . end($extension);
             $uploader->save($path, $imagename);
             $this->save_in_db($userid, $imagename, $image_id);
             //echo Mage::helper("adminhtml")->getUrl("adminhtml/order/photomanager/",array("order"=>$order_id));exit;
             $this->send_notification($userid, $order_id);
             $this->_redirectUrl(Mage::helper("adminhtml")->getUrl("adminhtml/order/photomanager/", array("order" => $order_id)));
         } catch (Exception $e) {
             echo $e->getMessage();
         }
     }
 }
예제 #15
0
파일: Image.php 프로젝트: sixg/mkAnagh
 public function UploadImage()
 {
     $data = array();
     $vendorPost = Mage::app()->getRequest()->getParam('vendor');
     if (isset($_FILES['vendor']['name'])) {
         foreach ($_FILES['vendor']['name'] as $fieldName => $value) {
             if (isset($_FILES['vendor']['name'][$fieldName]) && file_exists($_FILES['vendor']['tmp_name'][$fieldName])) {
                 $uploader = new Varien_File_Uploader("vendor[{$fieldName}]");
                 $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                 // or pdf or anything
                 $uploader->setAllowRenameFiles(false);
                 $uploader->setFilesDispersion(false);
                 $path = Mage::getBaseDir('media') . DS . 'ced' . DS . 'csmaketplace' . DS . 'vendor' . DS;
                 $extension = pathinfo($_FILES['vendor']['name'][$fieldName], PATHINFO_EXTENSION);
                 $fileName = $fieldName . time() . '.' . $extension;
                 $uploader->save($path, $fileName);
                 $data[$fieldName] = 'ced/csmaketplace/vendor/' . $fileName;
             } else {
                 if (isset($vendorPost[$fieldName]['delete']) && $vendorPost[$fieldName]['delete'] == 1) {
                     $data[$fieldName] = '';
                     $imageName = explode('/', $vendorPost[$fieldName]['value']);
                     $imageName = $imageName[count($imageName) - 1];
                     unlink(Mage::getBaseDir('media') . DS . 'ced' . DS . 'csmaketplace' . DS . 'vendor' . DS . $imageName);
                 } else {
                     unset($data[$fieldName]);
                 }
             }
         }
     }
     return $data;
 }
예제 #16
0
파일: Images.php 프로젝트: rcclaudrey/dev
 function saveImage($imageType, $_attributeId, $_optionId)
 {
     $imagekey = "{$imageType}-{$_attributeId}-{$_optionId}";
     if (isset($_FILES[$imagekey]['error']) && $_FILES[$imagekey]['error'] == 0) {
         try {
             /* Starting upload */
             $uploader = new Varien_File_Uploader($imagekey);
             $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
             $uploader->setAllowRenameFiles(false);
             $uploader->setFilesDispersion(false);
             $path = Mage::getBaseDir('media') . DS . 'colorswatch' . DS . 'image' . DS . $imageType . DS . $_attributeId . DS . $_optionId . DS;
             if (!is_writable(Mage::getBaseDir('media'))) {
                 throw new Exception('Magento Color Swatch extension is not able to write images in your ' . Mage::getBaseDir('media') . " directory.");
             }
             if ($uploader->save($path, $_FILES[$imagekey]['name'])) {
                 /* start clear cache */
                 foreach (glob($path . '*') as $cachePath) {
                     if (is_dir($cachePath) && is_file($cachePath . DS . $this->getData($imageType))) {
                         unlink($cachePath . DS . $this->getData($imageType));
                     }
                 }
                 /* end clear cache */
                 $this->setData($imageType, $_FILES[$imagekey]['name']);
             } else {
                 throw new Exception("Varien_File_Uploader class not upload image correct, please check your GD setting");
             }
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError(" {$e->getMessage()}");
             return false;
         }
     }
     return $this;
 }
 public function saveAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         if (isset($_FILES['content_bg_img']['name']) && $_FILES['content_bg_img']['name'] != null) {
             $result['file'] = '';
             try {
                 /* Starting upload */
                 $uploader = new Varien_File_Uploader('content_bg_img');
                 // Any extention would work
                 $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                 $uploader->setAllowRenameFiles(true);
                 // Set the file upload mode
                 // false -> get the file directly in the specified folder
                 // true -> get the file in the product like folders
                 //	(file.jpg will go in something like /media/f/i/file.jpg)
                 $uploader->setFilesDispersion(false);
                 // We set media as the upload dir
                 $path = Mage::getBaseDir('media') . DS . 'queldorei/shopper' . DS;
                 $result = $uploader->save($path, $_FILES['content_bg_img']['name']);
             } catch (Exception $e) {
                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage() . '  ' . $path);
                 Mage::getSingleton('adminhtml/session')->setFormData($data);
                 $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
                 return;
             }
             $data['content_bg_img'] = 'queldorei/shopper/' . $result['file'];
         } else {
             if (isset($data['content_bg_img']['delete']) && $data['content_bg_img']['delete'] == 1) {
                 $data['content_bg_img'] = '';
             } else {
                 unset($data['content_bg_img']);
             }
         }
         $model = Mage::getModel('shoppercategories/shoppercategories');
         $model->setData($data)->setId($this->getRequest()->getParam('id'));
         try {
             if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
                 $model->setCreatedTime(now())->setUpdateTime(now());
             } else {
                 $model->setUpdateTime(now());
             }
             $model->save();
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('shoppercategories')->__('Color Scheme was successfully saved'));
             Mage::getSingleton('adminhtml/session')->setFormData(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')->setFormData($data);
             $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
             return;
         }
     }
     Mage::getSingleton('adminhtml/session')->addError(Mage::helper('shoppercategories')->__('Unable to find item to save'));
     $this->_redirect('*/*/');
 }
예제 #18
0
파일: Http.php 프로젝트: Airmal/Magento-Em
    public function loadFile()
    {
        if (!$_FILES) {
            ?>
<form method="POST" enctype="multipart/form-data">
File to upload: <input type="file" name="io_file"/> <input type="submit" value="Upload"/>
</form>
<?php 
            exit;
        }
        if (!empty($_FILES['io_file']['tmp_name'])) {
            //$this->setData(file_get_contents($_FILES['io_file']['tmp_name']));
            $uploader = new Varien_File_Uploader('io_file');
            $uploader->setAllowedExtensions(array('csv', 'xml'));
            $path = Mage::app()->getConfig()->getTempVarDir() . '/import/';
            $uploader->save($path);
            if ($uploadFile = $uploader->getUploadedFileName()) {
                $session = Mage::getModel('dataflow/session');
                $session->setCreatedDate(date('Y-m-d H:i:s'));
                $session->setDirection('import');
                $session->setUserId(Mage::getSingleton('admin/session')->getUser()->getId());
                $session->save();
                $sessionId = $session->getId();
                $newFilename = 'import_' . $sessionId . '_' . $uploadFile;
                rename($path . $uploadFile, $path . $newFilename);
                $session->setFile($newFilename);
                $session->save();
                $this->setData(file_get_contents($path . $newFilename));
                Mage::register('current_dataflow_session_id', $sessionId);
            }
        }
        return $this;
    }
 public function changebackgroundAction()
 {
     $filename = '';
     if (isset($_FILES['change-background']['name']) && $_FILES['change-background']['name'] != '') {
         try {
             /* Starting upload */
             $uploader = new Varien_File_Uploader('change-background');
             // Any extention would work
             $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
             $uploader->setAllowRenameFiles(false);
             // Set the file upload mode
             // false -> get the file directly in the specified folder
             // true -> get the file in the product like folders
             //    (file.jpg will go in something like /media/f/i/file.jpg)
             $uploader->setFilesDispersion(false);
             // We set media as the upload dir
             $path = Mage::getBaseDir('media') . DS . 'magestore' . DS . 'pdfinvoiceplus' . DS . 'background';
             $result = $uploader->save($path, $_FILES['change-background']['name']);
             $filename = $result['file'];
             $this->getResponse()->setBody(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'magestore/pdfinvoiceplus/background/' . $filename);
         } catch (Exception $e) {
             $filename = $_FILES['change-background']['name'];
         }
     }
 }
예제 #20
0
 public function createpostAction()
 {
     if ($this->getRequest()->getPost()) {
         try {
             $data = $this->getRequest()->getParams();
             //echo '<pre>'; var_dump($data); echo '</pre>'; exit;
             if (isset($_FILES['image']['name']) && file_exists($_FILES['image']['tmp_name'])) {
                 $uploader = new Varien_File_Uploader('image');
                 $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                 $uploader->setAllowRenameFiles(false);
                 $uploader->setFilesDispersion(false);
                 $path = Mage::getBaseDir('media') . DS . 'magiccart' . DS . 'testimonial' . DS;
                 $uploader->save($path, $_FILES['image']['name']);
                 $data['image'] = 'magiccart/testimonial/' . $_FILES['image']['name'];
             }
             $autoApprove = Mage::helper('testimonial')->getGeneralCfg('autoApprove');
             if ($autoApprove) {
                 $data['status'] = Mage_Review_Model_Review::STATUS_APPROVED;
             }
             $model = Mage::getModel('testimonial/testimonial');
             $model->setData($data)->save();
             Mage::getModel('core/session')->addSuccess(Mage::helper('adminhtml')->__('Testimonial successfully submitted for admin approval.'));
             $this->_redirect('*/*');
         } catch (Exception $e) {
             Mage::getModel('core/session')->addError($e->getMessage());
             $this->_redirect('*/*');
             //return;
         }
     }
 }
예제 #21
0
 /**
  * Save form action
  */
 public function saveAction()
 {
     if ($this->getRequest()->getPost()) {
         try {
             $data = $this->getRequest()->getPost();
             if (isset($_FILES['testimonial_img']['name']) and file_exists($_FILES['testimonial_img']['tmp_name'])) {
                 $uploader = new Varien_File_Uploader('testimonial_img');
                 $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                 $uploader->setAllowRenameFiles(false);
                 $uploader->setFilesDispersion(false);
                 $path = Mage::getBaseDir('media') . DS;
                 $uploader->save($path, $_FILES['testimonial_img']['name']);
                 $data['testimonial_img'] = $_FILES['testimonial_img']['name'];
             } else {
                 if (isset($data['testimonial_img']['delete']) && $data['testimonial_img']['delete'] == 1) {
                     $data['testimonial_img'] = '';
                 } else {
                     unset($data['testimonial_img']);
                 }
             }
             $model = Mage::getModel('turnkeye_testimonial/testimonial');
             $model->setData($data)->setTestimonialId($this->getRequest()->getParam('id'))->save();
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('turnkeye_testimonial')->__('Testimonial was successfully saved'));
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
             $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
             return;
         }
     }
     $this->_redirect('*/*/');
 }
예제 #22
0
 /**
  * Upload file controller action
  */
 public function uploadAction()
 {
     $type = $this->getRequest()->getParam('type');
     $tmpPath = '';
     if ($type == 'samples') {
         $tmpPath = Mage_Downloadable_Model_Sample::getBaseTmpPath();
     } elseif ($type == 'links') {
         $tmpPath = Mage_Downloadable_Model_Link::getBaseTmpPath();
     } elseif ($type == 'link_samples') {
         $tmpPath = Mage_Downloadable_Model_Link::getBaseSampleTmpPath();
     }
     $result = array();
     try {
         $uploader = new Varien_File_Uploader($type);
         $uploader->setAllowRenameFiles(true);
         $uploader->setFilesDispersion(true);
         $result = $uploader->save($tmpPath);
         if (isset($result['file'])) {
             $fullPath = rtrim($tmpPath, DS) . DS . ltrim($result['file'], DS);
             Mage::helper('core/file_storage_database')->saveFile($fullPath);
         }
         $result['cookie'] = array('name' => session_name(), 'value' => $this->_getSession()->getSessionId(), 'lifetime' => $this->_getSession()->getCookieLifetime(), 'path' => $this->_getSession()->getCookiePath(), 'domain' => $this->_getSession()->getCookieDomain());
     } catch (Exception $e) {
         $result = array('error' => $e->getMessage(), 'errorcode' => $e->getCode());
     }
     $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
 }
예제 #23
0
 protected function _uploadSwatches()
 {
     $thePath = Mage::getBaseDir('media') . DS . 'colorselectorplus' . DS . 'swatches' . DS;
     $deleteMe = Mage::app()->getRequest()->getPost('colorselectorplus_swatch_delete');
     if ($deleteMe) {
         foreach ($deleteMe as $optionId => $delete) {
             if ($delete) {
                 @unlink($thePath . $optionId . '.jpg');
             }
         }
     }
     if (isset($_FILES['colorselectorplus_swatch']) && isset($_FILES['colorselectorplus_swatch']['error'])) {
         foreach ($_FILES['colorselectorplus_swatch']['error'] as $optionId => $error) {
             try {
                 $uploader = new Varien_File_Uploader('colorselectorplus_swatch[' . $optionId . ']');
                 $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                 $uploader->setAllowRenameFiles(false);
                 $uploader->setFilesDispersion(false);
                 $uploader->save($thePath, $optionId . '.jpg');
             } catch (Exception $e) {
                 Mage::getSingleton('adminhtml/session')->addError($this->__($e->getMessage()));
             }
         }
     }
 }
 public function saveAction()
 {
     if ($this->getRequest()->getPost()) {
         try {
             $postData = $this->getRequest()->getPost();
             $slideshowModel = Mage::getModel('mp_slideshow/slideshow');
             $slidesPath = Mage::helper('mp_slideshow')->getSlidesPath();
             if (isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
                 try {
                     /* Starting upload */
                     $uploader = new Varien_File_Uploader('filename');
                     // Any extention would work
                     $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                     $uploader->setAllowRenameFiles(true);
                     // Set the file upload mode
                     // false -> get the file directly in the specified folder
                     // true -> get the file in the product like folders
                     //    (file.jpg will go in something like /media/f/i/file.jpg)
                     $uploader->setFilesDispersion(false);
                     // We set media as the upload dir
                     $path = Mage::getBaseDir('media') . DS . $slidesPath;
                     $result = $uploader->save($path, $_FILES['filename']['name']);
                     //For thumb
                     Mage::helper('mp_slideshow')->resizeImg($result['file'], 100, 75);
                     //For thumb ends
                     $test = $slidesPath . $result['file'];
                     //$postData['filename'] = $slidesPath.$result['file'];
                     if (isset($postData['filename']['delete']) && $postData['filename']['delete'] == 1) {
                         //Mage_Core_Model_Store::URL_TYPE_MEDIA. DS .$postData['filename']['value'];
                         unlink(Mage_Core_Model_Store::URL_TYPE_MEDIA . DS . $postData['filename']['value']);
                         unlink(Mage_Core_Model_Store::URL_TYPE_MEDIA . DS . Mage::helper('mp_slideshow')->getThumbsPath($postData['filename']['value']));
                     }
                     $postData['filename'] = $test;
                 } catch (Exception $e) {
                     $postData['filename'] = $_FILES['filename']['name'];
                 }
             } else {
                 if (isset($postData['filename']['delete']) && $postData['filename']['delete'] == 1) {
                     unlink(Mage_Core_Model_Store::URL_TYPE_MEDIA . DS . $postData['filename']['value']);
                     unlink(Mage_Core_Model_Store::URL_TYPE_MEDIA . DS . Mage::helper('mp_slideshow')->getThumbsPath($postData['filename']['value']));
                     $postData['filename'] = '';
                 } else {
                     unset($postData['filename']);
                 }
             }
             $slideshowModel->setData($postData)->setId($this->getRequest()->getParam('id'))->save();
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Slide item was successfully saved'));
             Mage::getSingleton('adminhtml/session')->setSlideshowData(false);
             $this->_redirect('*/*/');
             return;
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
             Mage::getSingleton('adminhtml/session')->setSlideshowData($this->getRequest()->getPost());
             $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
             return;
         }
     }
     $this->_redirect('*/*/');
 }
예제 #25
0
파일: Stats.php 프로젝트: ntnhan220488/ggm
 public function uploadImage(Varien_Object $object)
 {
     $imageFileSmall = $_FILES['groups']['tmp_name']['design']['fields']['small_inline_image']['value'];
     $imageFileBig = $_FILES['groups']['tmp_name']['design']['fields']['big_inline_image']['value'];
     $absolute_path = Mage::getBaseDir('media') . DS;
     $relative_path = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
     if (!empty($imageFileSmall)) {
         //Mage::getDesign()->getSkinBaseDir() . DS . 'images' . DS . 'widget';
         // File Upload
         try {
             $file = array();
             $file['tmp_name'] = $_FILES['groups']['tmp_name']['design']['fields']['small_inline_image']['value'];
             $file['name'] = $_FILES['groups']['name']['design']['fields']['small_inline_image']['value'];
             $uploader = new Varien_File_Uploader($file);
             $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
             $uploader->setAllowRenameFiles(false);
             $uploader->setFilesDispersion(false);
             $test = $uploader->save($absolute_path, 'j2t_image_small.' . $this->getExtension($file['name']));
             $resizeFolder = "j2t_resized";
             $imageResizedPath = Mage::getBaseDir("media") . DS . $resizeFolder . DS . 'j2t_image_small.' . $this->getExtension($file['name']);
             if (is_file($imageResizedPath)) {
                 unlink($imageResizedPath);
             }
             if (!$test) {
                 $message = Mage::helper('rewardpoints')->__('Error when submitting image');
                 Mage::getSingleton('adminhtml/session')->addError($message);
             }
         } catch (Exception $e) {
             /*Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
               return $this;*/
         }
         // Your uploaded file Url will be
         //echo $file_url = $relative_path.$files;
     }
     if (!empty($imageFileBig)) {
         // File Upload
         try {
             $file = array();
             $file['tmp_name'] = $_FILES['groups']['tmp_name']['design']['fields']['big_inline_image']['value'];
             $file['name'] = $_FILES['groups']['name']['design']['fields']['big_inline_image']['value'];
             $uploader = new Varien_File_Uploader($file);
             $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
             $uploader->setAllowRenameFiles(false);
             $uploader->setFilesDispersion(false);
             $test = $uploader->save($absolute_path, 'j2t_image_big.' . $this->getExtension($file['name']));
             $imageResizedPath = Mage::getBaseDir("media") . DS . $resizeFolder . DS . 'j2t_image_big.' . $this->getExtension($file['name']);
             if (is_file($imageResizedPath)) {
                 unlink($imageResizedPath);
             }
             if (!$test) {
                 $message = Mage::helper('rewardpoints')->__('Error when submitting image');
                 Mage::getSingleton('adminhtml/session')->addError($message);
             }
         } catch (Exception $e) {
             /*Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); 
               return $this;*/
         }
     }
 }
 public function saveAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         $result = array();
         if (isset($_FILES['style_image']['name']) && $_FILES['style_image']['name'] != '') {
             try {
                 /* Starting upload */
                 $uploader = new Varien_File_Uploader('style_image');
                 // Any extention would work
                 $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                 $uploader->setAllowRenameFiles(true);
                 // Set the file upload mode
                 // false -> get the file directly in the specified folder
                 // true -> get the file in the product like folders
                 //	(file.jpg will go in something like /media/f/i/file.jpg)
                 $uploader->setFilesDispersion(true);
                 // We set media as the upload dir
                 $path = Mage::getBaseDir('media') . DS . 'highslide' . DS . 'images' . DS;
                 $result = $uploader->save($path, $_FILES['style_image']['name']);
             } catch (Exception $e) {
             }
         }
         //this way the name is saved in DB
         if (!empty($result['file'])) {
             $data['style_image'] = 'highslide/images' . $result['file'];
         } else {
             if ($data['style_image']['delete']) {
                 $data['style_image'] = '';
             } else {
                 unset($data['style_image']);
             }
         }
         $model = Mage::getModel('measurementadmin/measurementstyle');
         $model->setData($data)->setId($this->getRequest()->getParam('id'));
         try {
             if ($model->getDateAdded == NULL || $model->getLastModified() == NULL) {
                 $model->setDateAdded(now())->setLastModified(now());
             } else {
                 $model->setLastModified(now());
             }
             $model->save();
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('measurementadmin')->__('Item was successfully saved'));
             Mage::getSingleton('adminhtml/session')->setFormData(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')->setFormData($data);
             $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
             return;
         }
     }
     Mage::getSingleton('adminhtml/session')->addError(Mage::helper('measurement')->__('Unable to find item to save'));
     $this->_redirect('*/*/');
 }
예제 #27
0
 public function saveAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         if (isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
             try {
                 /* Starting upload */
                 $uploader = new Varien_File_Uploader('filename');
                 // Any extention would work
                 $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                 $uploader->setAllowRenameFiles(false);
                 // Set the file upload mode
                 // false -> get the file directly in the specified folder
                 // true -> get the file in the product like folders
                 //	(file.jpg will go in something like /media/f/i/file.jpg)
                 $uploader->setFilesDispersion(false);
                 // We set media as the upload dir
                 $path = Mage::getBaseDir('media') . DS;
                 $uploader->save($path, $_FILES['filename']['name']);
             } catch (Exception $e) {
             }
             //this way the name is saved in DB
             $data['filename'] = $_FILES['filename']['name'];
         }
         $model = Mage::getModel('managelicense/managelicense');
         $model->setData($data)->setId($this->getRequest()->getParam('id'));
         try {
             if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
                 $model->setCreatedTime(now())->setUpdateTime(now());
                 if ($model->getStatus() == 2) {
                     $model->setActiveDate(now());
                     $domain = $model->getMagentoUrl();
                     $extension = $model->getExtension();
                     $rendkey = Mage::helper('managelicense')->getKey($extension, $domain);
                     $model->setKeyActive($rendkey);
                 } else {
                     $model->setKeyActive("");
                 }
             } else {
                 $model->setUpdateTime(now());
             }
             $model->save();
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('managelicense')->__('Item was successfully saved'));
             Mage::getSingleton('adminhtml/session')->setFormData(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')->setFormData($data);
             $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
             return;
         }
     }
     Mage::getSingleton('adminhtml/session')->addError(Mage::helper('managelicense')->__('Unable to find item to save'));
     $this->_redirect('*/*/');
 }
예제 #28
0
 public function saveAction()
 {
     $id = $this->getRequest()->getParam('id');
     $model = Mage::getModel('amshopby/value')->load($id);
     $filterId = $model->getFilterId();
     $data = $this->getRequest()->getPost();
     if (!$data) {
         Mage::getSingleton('adminhtml/session')->addError(Mage::helper('amshopby')->__('Unable to find an option to save'));
         $this->_redirect('*/adminhtml_filter/');
     }
     //upload images
     $path = Mage::getBaseDir('media') . DS . 'amshopby' . DS;
     $imagesTypes = array('big', 'small', 'medium', 'small_hover');
     foreach ($imagesTypes as $type) {
         $field = 'img_' . $type;
         $isRemove = isset($data['remove_' . $field]);
         $hasNew = !empty($_FILES[$field]['name']);
         try {
             // remove the old file
             if ($isRemove || $hasNew) {
                 $oldName = $model->getData($field);
                 if ($oldName) {
                     @unlink($path . $oldName);
                     $data[$field] = '';
                 }
             }
             // upload a new if any
             if (!$isRemove && $hasNew) {
                 $newName = $type . $id;
                 $newName .= '.' . strtolower(substr(strrchr($_FILES[$field]['name'], '.'), 1));
                 $uploader = new Varien_File_Uploader($field);
                 $uploader->setFilesDispersion(false);
                 $uploader->setAllowRenameFiles(false);
                 $uploader->setAllowedExtensions(array('png', 'gif', 'jpg', 'jpeg'));
                 $uploader->save($path, $newName);
                 $data[$field] = $newName;
             }
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
         }
     }
     try {
         $model->setData($data)->setId($id);
         $model->save();
         Mage::getSingleton('adminhtml/session')->setFormData(false);
         $msg = Mage::helper('amshopby')->__('Option properties have been successfully saved');
         Mage::getSingleton('adminhtml/session')->addSuccess($msg);
         if ($this->getRequest()->getParam('continue')) {
             $this->_redirect('*/*/edit', array('id' => $model->getId()));
         } else {
             $this->_redirect('*/adminhtml_filter/edit', array('id' => $filterId, 'tab' => 'values'));
         }
     } catch (Exception $e) {
         Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
         Mage::getSingleton('adminhtml/session')->setFormData($data);
         $this->_redirect('*/*/edit', array('id' => $id));
     }
     $this->invalidateCache();
 }
 public function saveAction()
 {
     $data = $this->getRequest()->getPost();
     if ($data && isset($data['image_top_left_x']) && isset($data['image_top_left_y']) && isset($data['image_bottom_right_x']) && isset($data['image_bottom_right_y'])) {
         $model = Mage::getModel('wallprint/background');
         $id = $this->getRequest()->getParam('id');
         if ($id) {
             $model->load($id);
         }
         if (isset($_FILES['image_path']['name']) and file_exists($_FILES['image_path']['tmp_name'])) {
             try {
                 $uploader = new Varien_File_Uploader('image_path');
                 $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                 $uploader->setAllowRenameFiles(false);
                 $uploader->setFilesDispersion(false);
                 $path = 'media/' . VMalanka_WallPrint_Helper_Data::BACKGROUND_IMAGE_MEDIA_PATH;
                 $uploader->save($path, $_FILES['image_path']['name']);
                 $data['image_path'] = $_FILES['image_path']['name'];
             } catch (Exception $e) {
                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
                 if ($model && $model->getId()) {
                     $this->_redirect('*/*/edit', array('id' => $model->getId()));
                 } else {
                     $this->_redirect('*/*/');
                 }
             }
         }
         $data['image_coordinates'] = serialize(array($data['image_top_left_x'], $data['image_top_left_y'], $data['image_bottom_right_x'], $data['image_bottom_right_y']));
         $model->setData($data);
         Mage::getSingleton('adminhtml/session')->setFormData($data);
         try {
             if ($id) {
                 $model->setId($id);
             }
             $model->save();
             if (!$model->getId()) {
                 Mage::throwException(Mage::helper('wallprint')->__('Error saving image'));
             }
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('wallprint')->__('Image was successfully saved'));
             Mage::getSingleton('adminhtml/session')->setFormData(false);
             if ($this->getRequest()->getParam('back')) {
                 $this->_redirect('*/*/edit', array('id' => $model->getId()));
             } else {
                 $this->_redirect('*/*/');
             }
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
             if ($model && $model->getId()) {
                 $this->_redirect('*/*/edit', array('id' => $model->getId()));
             } else {
                 $this->_redirect('*/*/');
             }
         }
         return;
     }
     Mage::getSingleton('adminhtml/session')->addError(Mage::helper('wallprint')->__('No data found to save'));
     $this->_redirect('*/*/');
 }
예제 #30
0
 public function saveAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         if (isset($_FILES['image']['name']) && $_FILES['image']['name'] != '') {
             try {
                 $uploader = new Varien_File_Uploader('image');
                 $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                 $uploader->setAllowRenameFiles(true);
                 // Set the file upload mode
                 // false -> get the file directly in the specified folder
                 // true -> get the file in the product like folders
                 //	(file.jpg will go in something like /media/f/i/file.jpg)
                 $uploader->setFilesDispersion(false);
                 // We set media as the upload dir
                 $path = Mage::getBaseDir('media') . DS . 'magiccart' . DS . 'testimonial' . DS;
                 $result = $uploader->save($path, $_FILES['image']['name']);
                 //this way the name is saved in DB
                 $data['image'] = 'magiccart/testimonial/' . $result['file'];
             } catch (Exception $e) {
             }
         } else {
             if (isset($data['image']['delete']) && $data['image']['delete'] == 1) {
                 $data['image'] = '';
             } else {
                 unset($data['image']);
             }
         }
         if (isset($data['stores'])) {
             $data['stores'] = implode(',', $data['stores']);
         }
         //var_dump($data);die;
         $model = Mage::getModel('testimonial/testimonial');
         $model->setData($data)->setId($this->getRequest()->getParam('id'));
         try {
             if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
                 $model->setCreatedTime(now())->setUpdateTime(now());
             } else {
                 $model->setUpdateTime(now());
             }
             $model->save();
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('testimonial')->__('Item was successfully saved'));
             Mage::getSingleton('adminhtml/session')->setFormData(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')->setFormData($data);
             $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
             return;
         }
     }
     Mage::getSingleton('adminhtml/session')->addError(Mage::helper('testimonial')->__('Unable to find testimonial to save'));
     $this->_redirect('*/*/');
 }