コード例 #1
0
ファイル: File.php プロジェクト: riker09/EasyTemplate
 public function beforeFieldSave($value, $oldValue)
 {
     $value = parent::beforeFieldSave($value, $oldValue);
     $template = $this->getTemplate();
     /** @var $fileHelper Webguys_Easytemplate_Helper_File */
     $fileHelper = Mage::helper('easytemplate/file');
     $destinationPath = $fileHelper->getDestinationFilePath($template->getGroupId(), $template->getId());
     if ($oldValue && ($value && $oldValue != $value || $this->_deleteFile)) {
         // Delete the old file
         $oldFilePath = sprintf('%s/%s', $destinationPath, $oldValue);
         if (file_exists($oldFilePath)) {
             @unlink($oldFilePath);
         }
     }
     if ($value) {
         $fileHelper->createTmpPath($template->getGroupId(), $template->getId());
         if ($this->uploadComplete()) {
             $uploaderData = array('tmp_name' => $this->extractFilePostInformation('tmp_name'), 'name' => $value);
             $uploader = new Mage_Core_Model_File_Uploader($uploaderData);
             //$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png','pdf'));
             $uploader->addValidateCallback('easytemplate_template_file', $fileHelper, 'validateUploadFile');
             $uploader->setAllowRenameFiles(false);
             $uploader->setFilesDispersion(false);
             $result = $uploader->save($destinationPath);
             Mage::dispatchEvent('easytemplate_upload_file_after', array('result' => $result));
             $value = $result['file'];
         } else {
             // TODO: Error handling
         }
     }
     return $value;
 }
コード例 #2
0
 public function uploadAction()
 {
     try {
         $pattern = "/([0-9]+\\.[0-9]+\\.[0-9]+)(?:\\.[0-9]+)*/";
         $matches = array();
         preg_match($pattern, Mage::getVersion(), $matches);
         if (version_compare($matches[1], '1.5.1', '<')) {
             $uploader = new Varien_File_Uploader('image');
         } else {
             $uploader = new Mage_Core_Model_File_Uploader('image');
         }
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->addValidateCallback('catalog_product_image', Mage::helper('catalog/image'), 'validateUploadFile');
         $uploader->setAllowRenameFiles(true);
         $uploader->setFilesDispersion(true);
         $result = $uploader->save($this->getMagicslideshowBaseMediaPath());
         /**
          * Workaround for prototype 1.7 methods "isJSON", "evalJSON" on Windows OS
          */
         $result['tmp_name'] = str_replace(DS, "/", $result['tmp_name']);
         $result['path'] = str_replace(DS, "/", $result['path']);
         $result['url'] = $this->getMagicslideshowMediaUrl($result['file']);
         $result['file'] = $result['file'];
         $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));
 }
コード例 #3
0
 public function saveFields(Varien_Event_Observer $observer)
 {
     $model = $observer->getEvent()->getPage();
     $request = $observer->getEvent()->getRequest();
     if (isset($_FILES['image']['name']) && $_FILES['image']['name'] != '') {
         try {
             $uploader = new Mage_Core_Model_File_Uploader('image');
             $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
             $uploader->setAllowRenameFiles(true);
             $uploader->setFilesDispersion(false);
             $dirPath = Mage::getBaseDir('media') . DS . 'page' . DS;
             $result = $uploader->save($dirPath, $_FILES['image']['name']);
         } catch (Exception $e) {
             Mage::log($e->getMessage());
         }
         $model->setImage('page/' . $result['file']);
     } else {
         $data = $request->getPost();
         if (isset($data['image']) && isset($data['image']['delete']) && $data['image']['delete'] == 1) {
             $model->setImage(false);
         } elseif (isset($data['image']) && is_array($data['image'])) {
             $model->setImage($data['image']['value']);
         }
     }
     if (empty($model->getPageType())) {
         $model->setPageType(null);
     }
 }
コード例 #4
0
ファイル: FileController.php プロジェクト: cewolf2002/magento
 /**
  * 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 Mage_Core_Model_File_Uploader($type);
         $uploader->setAllowRenameFiles(true);
         $uploader->setFilesDispersion(true);
         $result = $uploader->save($tmpPath);
         /**
          * Workaround for prototype 1.7 methods "isJSON", "evalJSON" on Windows OS
          */
         $result['tmp_name'] = str_replace(DS, "/", $result['tmp_name']);
         $result['path'] = str_replace(DS, "/", $result['path']);
         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));
 }
コード例 #5
0
 /**
  * After save
  *
  * @param Varien_Object $object
  * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Image
  */
 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;
     }
     try {
         $uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->setAllowRenameFiles(true);
         $uploader->setFilesDispersion(true);
         $uploader->addValidateCallback(Mage_Core_Model_File_Validator_Image::NAME, new Mage_Core_Model_File_Validator_Image(), "validate");
         $uploader->save(Mage::getBaseDir('media') . '/catalog/product');
         $fileName = $uploader->getUploadedFileName();
         if ($fileName) {
             $object->setData($this->getAttribute()->getName(), $fileName);
             $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
         }
     } catch (Exception $e) {
         return $this;
     }
     return $this;
 }
コード例 #6
0
    public function uploadAction()
    {
        try {
            $uploader = new Mage_Core_Model_File_Uploader('file');
            $uploader->setAllowedExtensions();
            $uploader->setAllowRenameFiles(true);
            $uploader->setFilesDispersion(true);
            $result = $uploader->save(
                            Mage::getSingleton('catalog/product_media_config')->getBaseTmpMediaPath()
            );

            $result['url'] = Mage::getSingleton('catalog/product_media_config')->getTmpMediaUrl($result['file']);
            $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));
    }
コード例 #7
0
ファイル: FileController.php プロジェクト: relue/magento2
 /**
  * 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 Mage_Core_Model_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('Mage_Core_Helper_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('Mage_Core_Helper_Data')->jsonEncode($result));
 }
コード例 #8
0
ファイル: ProductController.php プロジェクト: enjoy2000/gemz
 public function importAction()
 {
     try {
         $productId = $this->getRequest()->getParam('id');
         $fileName = $this->getRequest()->getParam('Filename');
         $path = Mage::getBaseDir('var') . DS . 'import' . DS;
         $uploader = new Mage_Core_Model_File_Uploader('file');
         $uploader->setAllowedExtensions(array('csv'));
         $uploader->setAllowRenameFiles(false);
         $uploader->setFilesDispersion(false);
         $result = $uploader->save($path, $fileName);
         $io = new Varien_Io_File();
         $io->open(array('path' => $path));
         $io->streamOpen($path . $fileName, 'r');
         $io->streamLock(true);
         while ($data = $io->streamReadCsv(';', '"')) {
             if ($data[0]) {
                 $model = Mage::getModel('giftcards/pregenerated')->load($data[0], 'card_code');
                 if ($model->getId()) {
                     continue;
                 }
                 $model->setCardCode($data[0]);
                 $model->setCardStatus(1);
                 $model->setProductId($productId);
                 $model->save();
             } else {
                 continue;
             }
         }
     } catch (Exception $e) {
         $result = array('error' => $e->getMessage(), 'errorcode' => $e->getCode());
     }
     $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
 }
コード例 #9
0
 /**
  * Save uploaded file before saving config value
  *
  * @return Mage_Backend_Model_Config_Backend_File
  */
 protected function _beforeSave()
 {
     $value = $this->getValue();
     $tmpName = $this->_requestData->getTmpName($this->getPath());
     if ($tmpName) {
         $uploadDir = $this->_getUploadDir();
         try {
             $file = array();
             $file['tmp_name'] = $tmpName;
             $file['name'] = $this->_requestData->getName($this->getPath());
             $uploader = new Mage_Core_Model_File_Uploader($file);
             $uploader->setAllowedExtensions($this->_getAllowedExtensions());
             $uploader->setAllowRenameFiles(true);
             $uploader->addValidateCallback('size', $this, 'validateMaxSize');
             $result = $uploader->save($uploadDir);
         } catch (Exception $e) {
             Mage::throwException($e->getMessage());
             return $this;
         }
         $filename = $result['file'];
         if ($filename) {
             if ($this->_addWhetherScopeInfo()) {
                 $filename = $this->_prependScopeInfo($filename);
             }
             $this->setValue($filename);
         }
     } else {
         if (is_array($value) && !empty($value['delete'])) {
             $this->setValue('');
         } else {
             $this->unsValue();
         }
     }
     return $this;
 }
コード例 #10
0
ファイル: Image.php プロジェクト: natxetee/magento2
 /**
  * Save uploaded file and set its name to category
  *
  * @param Varien_Object $object
  * @return Mage_Catalog_Model_Category_Attribute_Backend_Image
  */
 public function afterSave($object)
 {
     $value = $object->getData($this->getAttribute()->getName());
     // if no image was set - nothing to do
     if (empty($value) && empty($_FILES)) {
         return $this;
     }
     if (is_array($value) && !empty($value['delete'])) {
         $object->setData($this->getAttribute()->getName(), '');
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
         return $this;
     }
     $path = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category' . DS;
     try {
         $uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->setAllowRenameFiles(true);
         $result = $uploader->save($path);
         $object->setData($this->getAttribute()->getName(), $result['file']);
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
     } catch (Exception $e) {
         if ($e->getCode() != Mage_Core_Model_File_Uploader::TMP_NAME_EMPTY) {
             Mage::logException($e);
         }
         /** @TODO ??? */
     }
     return $this;
 }
コード例 #11
0
 public function saveFlag(Varien_Event_Observer $observer)
 {
     $store = $observer->getEvent()->getStore();
     $data = Mage::app()->getRequest()->getPost();
     if (!empty($_FILES)) {
         if (isset($_FILES['flag']['name']) && $_FILES['flag']['name'] != '') {
             try {
                 $uploader = new Mage_Core_Model_File_Uploader('flag');
                 $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png', 'svg'));
                 $uploader->setAllowRenameFiles(true);
                 $uploader->setFilesDispersion(false);
                 $dirPath = Mage::getBaseDir('media') . DS . 'store_flag';
                 $result = $uploader->save($dirPath, $_FILES['flag']['name']);
             } catch (Exception $e) {
                 Mage::log($e->getMessage());
             }
             $store->setFlag('store_flag' . $result['file']);
         } elseif (isset($data['flag']) && is_array($data['flag'])) {
             if (isset($data['flag']['delete']) && $data['flag']['delete'] === "1") {
                 $store->setFlag(null);
             } else {
                 $store->setFlag($data['flag']['value']);
             }
         }
     }
 }
コード例 #12
0
ファイル: File.php プロジェクト: jahvi/FileUploadAttribute
 /**
  * After attribute is saved upload file to media
  * folder and save it to its associated product.
  *
  * @param  Mage_Catalog_Model_Product $object
  * @return Jvs_FileAttribute_Model_Attribute_Backend_File
  */
 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;
     }
     try {
         $uploadedFile = new Varien_Object();
         $uploadedFile->setData('name', $this->getAttribute()->getName());
         $uploadedFile->setData('allowed_extensions', array('jpg', 'jpeg', 'gif', 'png', 'tif', 'tiff', 'mpg', 'mpeg', 'mp3', 'wav', 'pdf', 'txt'));
         Mage::dispatchEvent('jvs_fileattribute_allowed_extensions', array('file' => $uploadedFile));
         $uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
         $uploader->setAllowedExtensions($uploadedFile->getData('allowed_extensions'));
         $uploader->setAllowRenameFiles(true);
         $uploader->setFilesDispersion(true);
         $uploader->save(Mage::getBaseDir('media') . '/catalog/product');
     } catch (Exception $e) {
         return $this;
     }
     $fileName = $uploader->getUploadedFileName();
     if ($fileName) {
         $object->setData($this->getAttribute()->getName(), $fileName);
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
     }
     return $this;
 }
コード例 #13
0
ファイル: File.php プロジェクト: natxetee/magento2
 /**
  * Save uploaded file before saving config value
  *
  * @return Mage_Adminhtml_Model_System_Config_Backend_File
  */
 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();
             $tmpName = $_FILES['groups']['tmp_name'];
             $file['tmp_name'] = $tmpName[$this->getGroupId()]['fields'][$this->getField()]['value'];
             $name = $_FILES['groups']['name'];
             $file['name'] = $name[$this->getGroupId()]['fields'][$this->getField()]['value'];
             $uploader = new Mage_Core_Model_File_Uploader($file);
             $uploader->setAllowedExtensions($this->_getAllowedExtensions());
             $uploader->setAllowRenameFiles(true);
             $result = $uploader->save($uploadDir);
         } catch (Exception $e) {
             Mage::throwException($e->getMessage());
             return $this;
         }
         $filename = $result['file'];
         if ($filename) {
             if ($this->_addWhetherScopeInfo()) {
                 $filename = $this->_prependScopeInfo($filename);
             }
             $this->setValue($filename);
         }
     }
     return $this;
 }
コード例 #14
0
ファイル: Image.php プロジェクト: lynxtdc/aromaworks
 /**
  * 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 Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->setAllowRenameFiles(true);
         $uploader->addValidateCallback(Mage_Core_Model_File_Validator_Image::NAME, new Mage_Core_Model_File_Validator_Image(), "validate");
         $result = $uploader->save($path);
         $object->setData($this->getAttribute()->getName(), $result['file']);
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
     } catch (Exception $e) {
         if ($e->getCode() != Mage_Core_Model_File_Uploader::TMP_NAME_EMPTY) {
             Mage::logException($e);
         }
         /** @TODO ??? */
         return;
     }
 }
コード例 #15
0
 public function saveCustomOptionImages(Varien_Event_Observer $observer)
 {
     if (!isset($_FILES) || empty($_FILES) || !isset($_FILES['product'])) {
         return;
     }
     $product = $observer->getEvent()->getProduct();
     $productData = $observer->getEvent()->getRequest()->getPost('product');
     if (isset($productData['options']) && !$product->getOptionsReadonly()) {
         if (isset($_FILES['product']['name']['options'])) {
             $images = array();
             foreach ($_FILES['product'] as $attr => $options) {
                 if (isset($options['options'])) {
                     foreach ($options['options'] as $optionId => $values) {
                         if (isset($values['values'])) {
                             foreach ($values['values'] as $valueId => $data) {
                                 $key = 'option_' . $optionId . '_value_' . $valueId;
                                 if (!isset($images[$key])) {
                                     $images[$key] = array();
                                 }
                                 $images[$key][$attr] = $data['image'];
                             }
                         }
                     }
                 }
             }
             foreach ($images as $imageName => $imageData) {
                 $_FILES[$imageName] = $imageData;
             }
         }
         foreach ($productData['options'] as $optionId => $option) {
             if (!empty($option['values'])) {
                 foreach ($option['values'] as $valueId => $value) {
                     $imageName = 'option_' . $optionId . '_value_' . $valueId;
                     if (!isset($_FILES[$imageName]) || empty($_FILES[$imageName]) || $_FILES[$imageName]['name'] === "") {
                         continue;
                     }
                     try {
                         $uploader = new Mage_Core_Model_File_Uploader($imageName);
                         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                         $uploader->setAllowRenameFiles(true);
                         $uploader->setFilesDispersion(false);
                         $dirPath = Mage::getBaseDir('media') . DS . 'custom_option_image' . DS;
                         $result = $uploader->save($dirPath, $_FILES[$imageName]['name']);
                     } catch (Exception $e) {
                         Mage::log($e->getMessage());
                     }
                     $productData['options'][$optionId]['values'][$valueId]['image'] = 'custom_option_image/' . $result['file'];
                     $product->setCanSaveCustomOptions(true);
                 }
             }
         }
         $product->setProductOptions($productData['options']);
     }
 }
コード例 #16
0
 public function saveAction()
 {
     // check if data sent
     if ($data = $this->getRequest()->getPost()) {
         if (!empty($_FILES)) {
             foreach ($_FILES as $name => $fileData) {
                 if (isset($fileData['name']) && $fileData['name'] != '') {
                     try {
                         $uploader = new Mage_Core_Model_File_Uploader($name);
                         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png', 'svg'));
                         $uploader->setAllowRenameFiles(true);
                         $uploader->setFilesDispersion(false);
                         $dirPath = Mage::getBaseDir('media') . DS . 'block' . DS;
                         $result = $uploader->save($dirPath, $fileData['name']);
                     } catch (Exception $e) {
                         Mage::log($e->getMessage());
                     }
                     $data[$name] = 'block/' . $result['file'];
                 } elseif (isset($data[$name]) && is_array($data[$name])) {
                     $data[$name] = $data[$name]['value'];
                 }
             }
         }
         $data = $this->_filterDates($data, array('active_from', 'active_to'));
         //init model and set data
         $model = Mage::getModel('block/block');
         $model->setData($data);
         // try to save it
         try {
             // save the data
             $model->save();
             // display success message
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('block')->__('The block has been saved.'));
             // clear previously saved data from session
             Mage::getSingleton('adminhtml/session')->setFormData(false);
             // check if 'Save and Continue'
             if ($this->getRequest()->getParam('back')) {
                 $this->_redirect('*/*/edit', array('block_id' => $model->getId()));
                 return;
             }
             // go to grid
             $this->_redirect('*/*/');
             return;
         } catch (Mage_Core_Exception $e) {
             $this->_getSession()->addError($e->getMessage());
         } catch (Exception $e) {
             $this->_getSession()->addException($e, Mage::helper('block')->__('An error occurred while saving the block.'));
         }
         $this->_getSession()->setFormData($data);
         $this->_redirect('*/*/edit', array('block_id' => $this->getRequest()->getParam('block_id')));
         return;
     }
     $this->_redirect('*/*/');
 }
コード例 #17
0
 public function saveAction()
 {
     $data = $this->getRequest()->getParams();
     $uploader = new Mage_Core_Model_File_Uploader('file');
     $uploader->setAllowedExtensions(array('csv'));
     $uploader->setAllowRenameFiles(true);
     $path = Mage::getBaseDir('var') . DS . 'import';
     if (!file_exists($path)) {
         mkdir($path, 0777);
     }
     try {
         $result = $uploader->save($path);
         $fullPath = $result['path'] . DS . $result['file'];
         $csv = new Varien_File_Csv();
         $data = $csv->getData($fullPath);
         $items = array();
         if (count($data) > 1) {
             for ($i = 1; $i < count($data); $i++) {
                 $item = array();
                 for ($j = 0; $j < count($data[0]); $j++) {
                     if (isset($data[$i][$j]) && trim($data[$i][$j]) != '') {
                         $item[strtolower($data[0][$j])] = $data[$i][$j];
                     }
                 }
                 $items[] = $item;
             }
         }
         $resource = Mage::getSingleton('core/resource');
         $writeConnection = $resource->getConnection('core_write');
         $table = $resource->getTableName('seo/redirect');
         $table2 = $resource->getTableName('seo/redirect_store');
         $i = 0;
         foreach ($items as $item) {
             pr($item);
             if (!isset($item['url_from']) || !isset($item['url_to'])) {
                 continue;
             }
             $item = new Varien_Object($item);
             $query = "REPLACE {$table} SET\n                    url_from = '" . addslashes($item->getUrlFrom()) . "',\n                    url_to = '" . addslashes($item->getUrlTo()) . "',\n                    is_redirect_only_error_page = '" . addslashes($item->getIsRedirectOnlyErrorPage()) . "',\n                    comments = '" . addslashes($item->getComments()) . "',\n                    is_active = '" . addslashes($item->getIsActive()) . "';\n                    REPLACE {$table2} SET\n                        store_id = 0,\n                        redirect_id = LAST_INSERT_ID();\n                     ";
             $writeConnection->query($query);
             $i++;
         }
         Mage::getSingleton('adminhtml/session')->addSuccess('' . $i . ' records were inserted or updated');
     } catch (Exception $e) {
         Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
     }
     $this->_redirect('*/*/');
 }
コード例 #18
0
 public function loadAction()
 {
     $request = new Varien_Object($this->getRequest()->getParams());
     if ($request && $request->getKey()) {
         $uploader = new Mage_Core_Model_File_Uploader('file');
         $allowed = Mage::getSingleton('cms/wysiwyg_images_storage')->getAllowedExtensions('image');
         $uploader->setAllowedExtensions($allowed);
         $uploader->setAllowRenameFiles(true);
         $uploader->setFilesDispersion(false);
         $result = $uploader->save(Mage::helper('cms/wysiwyg_images')->getCurrentPath());
         $imageUrl = sprintf('/media/%s/%s', Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY, $result['file']);
         $array = array('filelink' => $imageUrl, 'filename' => $_FILES['file']['name']);
         echo stripslashes(json_encode($array));
         exit;
     }
 }
コード例 #19
0
 /**
  * Does some saving action
  *
  * @param  [type] $name name of the input field
  *
  * @return [string | false] filename or false on exception
  */
 public function saveImage($name)
 {
     $path = $this->getFullImagesDir();
     try {
         $uploader = new Mage_Core_Model_File_Uploader($name);
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->setAllowRenameFiles(true);
         $result = $uploader->save($path);
         return $result['file'];
     } catch (Exception $e) {
         if ($e->getCode() != Mage_Core_Model_File_Uploader::TMP_NAME_EMPTY) {
             Mage::logException($e);
         }
         return;
     }
 }
コード例 #20
0
 public function saveAction()
 {
     $data = $this->getRequest()->getParams();
     $uploader = new Mage_Core_Model_File_Uploader('file');
     $uploader->setAllowedExtensions(array('csv'));
     $uploader->setAllowRenameFiles(true);
     $path = Mage::getBaseDir('var') . DS . 'import';
     if (!file_exists($path)) {
         mkdir($path, 0777);
     }
     try {
         $result = $uploader->save($path);
         $fullPath = $result['path'] . DS . $result['file'];
         $csv = new Varien_File_Csv();
         $data = $csv->getData($fullPath);
         $items = array();
         if (count($data) > 1) {
             for ($i = 1; $i < count($data); $i++) {
                 $item = array();
                 for ($j = 0; $j < count($data[0]); $j++) {
                     if (isset($data[$i][$j]) && trim($data[$i][$j]) != '') {
                         $item[strtolower($data[0][$j])] = $data[$i][$j];
                     }
                 }
                 $items[] = $item;
             }
         }
         $resource = Mage::getSingleton('core/resource');
         $writeConnection = $resource->getConnection('core_write');
         $table = $resource->getTableName('seoautolink/link');
         $table2 = $resource->getTableName('seoautolink/link_store');
         $i = 0;
         foreach ($items as $item) {
             if (!isset($item['keyword'])) {
                 continue;
             }
             $item = new Varien_Object($item);
             $query = "REPLACE {$table} SET\n                    keyword = '" . addslashes($item->getKeyword()) . "',\n                    url = '" . addslashes($item->getUrl()) . "',\n                    url_title = '" . addslashes($item->getUrlTitle()) . "',\n                    url_target = '" . addslashes($item->getUrlTarget()) . "',\n                    is_nofollow = '" . (int) $item->getIsNofollow() . "',\n                    max_replacements = '" . (int) $item->getMaxReplacements() . "',\n                    sort_order = '" . (int) $item->getSortOrder() . "',\n                    occurence = '" . (int) $item->getOccurence() . "',\n                    is_active = '" . (int) $item->getIsActive() . "',\n                    created_at = '" . now() . "',\n                    updated_at = '" . now() . "';\n                    REPLACE {$table2} SET\n                        store_id = '" . (int) $item->getStoreId() . "',\n                        link_id = LAST_INSERT_ID();\n                     ";
             $writeConnection->query($query);
             $i++;
         }
         Mage::getSingleton('adminhtml/session')->addSuccess('' . $i . ' records were inserted or updated');
     } catch (Exception $e) {
         Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
     }
     $this->_redirect('*/*/');
 }
コード例 #21
0
ファイル: Image.php プロジェクト: kozinthetdbp/megamall
 /**
  * Return the root part of directory path for uploading
  *
  * @var string
  * @return string
  */
 protected function _beforeSave()
 {
     $value = $this->getValue();
     if ($_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value']) {
         $uploadDir = $this->_getUploadDir();
         try {
             $file = array();
             $tmpName = $_FILES['groups']['tmp_name'];
             $file['tmp_name'] = $tmpName[$this->getGroupId()]['fields'][$this->getField()]['value'];
             $name = $_FILES['groups']['name'];
             $file['name'] = $name[$this->getGroupId()]['fields'][$this->getField()]['value'];
             //Check exists
             if (file_exists($uploadDir . DS . $file['name'])) {
                 $msg = "+ " . Mage::helper('jmbasetheme')->__("Image with named %s was existed", $file['name']);
                 Mage::getSingleton('core/session')->addNotice($msg);
                 return $this;
             } else {
                 $uploader = new Mage_Core_Model_File_Uploader($file);
                 $uploader->setAllowedExtensions($this->_getAllowedExtensions());
                 $uploader->setAllowRenameFiles(true);
                 $maxImageSize = 2 * 1024;
                 //2MB
                 $this->setMaxUploadFileSize($maxImageSize);
                 $uploader->addValidateCallback('size', $this, 'validateMaxSize');
                 $result = $uploader->save($uploadDir);
             }
         } catch (Exception $e) {
             Mage::throwException($e->getMessage());
             return $this;
         }
         $filename = $result['file'];
         if ($filename) {
             if ($this->_addWhetherScopeInfo()) {
                 $filename = $this->_prependScopeInfo($filename);
             }
             $this->setValue($filename);
         }
     } else {
         if (is_array($value) && !empty($value['delete'])) {
             $this->setValue('');
         } else {
             $this->unsValue();
         }
     }
     return $this;
 }
コード例 #22
0
 public function _afterSave()
 {
     if (empty($_FILES['groups']['tmp_name']['purchaseorder']['fields']['paid_icon']['value'])) {
         return $this;
     }
     try {
         $_FILES['paid_icon'] = array('name' => $_FILES['groups']['name']['purchaseorder']['fields']['paid_icon']['value'], 'type' => $_FILES['groups']['type']['purchaseorder']['fields']['paid_icon']['value'], 'tmp_name' => $_FILES['groups']['tmp_name']['purchaseorder']['fields']['paid_icon']['value'], 'error' => $_FILES['groups']['error']['purchaseorder']['fields']['paid_icon']['value'], 'size' => $_FILES['groups']['size']['purchaseorder']['fields']['paid_icon']['value']);
         $path = Mage::helper('emjainteractive_purchaseordermanagement')->getIconMediaPath();
         $uploader = new Mage_Core_Model_File_Uploader('paid_icon');
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->setAllowRenameFiles(false);
         $result = $uploader->save($path);
     } catch (Exception $e) {
         Mage::logException($e);
         throw new Exception($e);
     }
 }
コード例 #23
0
ファイル: File.php プロジェクト: sagmahajan/aswan_release
 /**
  * Save uploaded file before saving config value
  *
  * @return Mage_Adminhtml_Model_System_Config_Backend_File
  */
 protected function _beforeSave()
 {
     /*
     print 'GroupID = '.$this->getGroupId().'<br>Field = '.$this->getField();
     print "<pre>";
     	print_r($_FILES);
     print "</pre>";
     die;
     */
     $value = $this->getValue();
     if ($_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value']) {
         //$uploadDir = $this->_getUploadDir();
         $uploadDir = Mage::getBaseDir('media') . DIRECTORY_SEPARATOR . 'productvideos' . DIRECTORY_SEPARATOR;
         try {
             $file = array();
             $tmpName = $_FILES['groups']['tmp_name'];
             $file['tmp_name'] = $tmpName[$this->getGroupId()]['fields'][$this->getField()]['value'];
             $name = $_FILES['groups']['name'];
             $file['name'] = $name[$this->getGroupId()]['fields'][$this->getField()]['value'];
             /* extra code added to add time stamp to file name to get latest on top */
             $file['name'] = date('YmdHis') . '_' . $file['name'];
             $uploader = new Mage_Core_Model_File_Uploader($file);
             $uploader->setAllowedExtensions($this->_getAllowedExtensions());
             $uploader->setAllowRenameFiles(true);
             $uploader->addValidateCallback('size', $this, 'validateMaxSize');
             $result = $uploader->save($uploadDir);
         } catch (Exception $e) {
             Mage::throwException($e->getMessage());
             return $this;
         }
         $filename = $result['file'];
         if ($filename) {
             if ($this->_addWhetherScopeInfo()) {
                 $filename = $this->_prependScopeInfo($filename);
             }
             $this->setValue($filename);
         }
     } else {
         if (is_array($value) && !empty($value['delete'])) {
             $this->setValue('');
         } else {
             $this->unsValue();
         }
     }
     return $this;
 }
コード例 #24
0
 /**
  * Return the root part of directory path for uploading
  *
  * @var string
  * @return string
  */
 protected function _beforeSave()
 {
     $value = $this->getValue();
     if ($_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value']) {
         $uploadDir = $this->_getUploadDir();
         try {
             $file = array();
             $tmpName = $_FILES['groups']['tmp_name'];
             $file['tmp_name'] = $tmpName[$this->getGroupId()]['fields'][$this->getField()]['value'];
             $name = $_FILES['groups']['name'];
             $file['name'] = $name[$this->getGroupId()]['fields'][$this->getField()]['value'];
             $url = getimagesize($uploadDir . DS . $file['name']);
             //print_r($url); returns an array
             if (is_array($url)) {
                 $fieldConfig = $this->getFieldConfig();
                 Mage::throwException($fieldConfig->label . Mage::helper('core')->__("with same name existed"));
             } else {
                 $uploader = new Mage_Core_Model_File_Uploader($file);
                 $uploader->setAllowedExtensions($this->_getAllowedExtensions());
                 $uploader->setAllowRenameFiles(true);
                 $uploader->addValidateCallback('size', $this, 'validateMaxSize');
                 $result = $uploader->save($uploadDir);
             }
         } catch (Exception $e) {
             Mage::throwException($e->getMessage());
             return $this;
         }
         $filename = $result['file'];
         if ($filename) {
             if ($this->_addWhetherScopeInfo()) {
                 $filename = $this->_prependScopeInfo($filename);
             }
             $this->setValue($filename);
         }
     } else {
         if (is_array($value) && !empty($value['delete'])) {
             $this->setValue('');
         } else {
             $this->unsValue();
         }
     }
     return $this;
 }
コード例 #25
0
ファイル: File.php プロジェクト: sagmahajan/aswan_release
 /**
  * Save uploaded file before saving config value
  *
  * @return Mage_Adminhtml_Model_System_Config_Backend_File
  */
 protected function _beforeSave()
 {
     $value = $this->getValue();
     if ($_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value']) {
         //$uploadDir = $this->_getUploadDir();
         $uploadDir = Mage::getStoreConfig('zipcodeimport/paths/zipcodeIn');
         try {
             $file = array();
             $tmpName = $_FILES['groups']['tmp_name'];
             $file['tmp_name'] = $tmpName[$this->getGroupId()]['fields'][$this->getField()]['value'];
             $name = $_FILES['groups']['name'];
             $file['name'] = $name[$this->getGroupId()]['fields'][$this->getField()]['value'];
             /* extra code added to add time stamp to file name to get latest on top */
             $file['name'] = date('YmdHis') . '_' . $file['name'];
             /*Extra code ends */
             $uploader = new Mage_Core_Model_File_Uploader($file);
             $uploader->setAllowedExtensions($this->_getAllowedExtensions());
             $uploader->setAllowRenameFiles(true);
             $uploader->addValidateCallback('size', $this, 'validateMaxSize');
             $result = $uploader->save($uploadDir);
         } catch (Exception $e) {
             Mage::throwException($e->getMessage());
             return $this;
         }
         $filename = $result['file'];
         if ($filename) {
             if ($this->_addWhetherScopeInfo()) {
                 $filename = $this->_prependScopeInfo($filename);
             }
             $this->setValue($filename);
         }
     } else {
         if (is_array($value) && !empty($value['delete'])) {
             $this->setValue('');
         } else {
             $this->unsValue();
         }
     }
     return $this;
 }
コード例 #26
0
 public function saveCurrencyFlags(Varien_Event_Observer $observer)
 {
     $currencyFlags = unserialize(Mage::getStoreConfig('currency/options/currencyflag', ""));
     $deleteFlags = Mage::app()->getRequest()->getParam('delete_currency_flag', null);
     if (!empty($deleteFlags)) {
         foreach ($deleteFlags as $currency => $delete) {
             unset($_FILES[$currency], $currencyFlags[$currency]);
         }
     }
     $fileUpload = false;
     foreach ($_FILES as $image) {
         if (isset($image['name']) && $image['name'] !== '') {
             $fileUpload = true;
         }
     }
     if ($fileUpload) {
         foreach ($_FILES as $currency => $image) {
             if (isset($image['name']) && $image['name'] != '') {
                 try {
                     $uploader = new Mage_Core_Model_File_Uploader($currency);
                     $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png', 'svg'));
                     $uploader->setAllowRenameFiles(true);
                     $uploader->setFilesDispersion(false);
                     $dirPath = Mage::getBaseDir('media') . DS . 'currencyflag' . DS;
                     $result = $uploader->save($dirPath, $image['name']);
                     $currencyFlags[$currency] = 'currencyflag' . DS . $result['file'];
                 } catch (Exception $e) {
                     Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
                 }
             }
         }
     }
     if (!empty($currencyFlags)) {
         $config = array('value' => serialize($currencyFlags));
     } else {
         $config = array('inherit' => 1);
     }
     Mage::getModel('adminhtml/config_data')->setSection('currency')->setWebsite(null)->setStore(null)->setGroups(array('options' => array('fields' => array('currencyflag' => $config))))->save();
     Mage::getSingleton('connect/session')->addSuccess(Mage::helper('adminhtml')->__('Custom currency flags were applied successfully.'));
 }
コード例 #27
0
ファイル: File.php プロジェクト: hientruong90/ee_14_installer
 /**
  * Save uploaded file before saving config value
  *
  * @return Mage_Adminhtml_Model_System_Config_Backend_File
  */
 protected function _beforeSave()
 {
     $value = $this->getValue();
     if ($_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value']) {
         $uploadDir = $this->_getUploadDir();
         try {
             $file = array();
             $tmpName = $_FILES['groups']['tmp_name'];
             $file['tmp_name'] = $tmpName[$this->getGroupId()]['fields'][$this->getField()]['value'];
             $name = $_FILES['groups']['name'];
             $file['name'] = $name[$this->getGroupId()]['fields'][$this->getField()]['value'];
             $uploader = new Mage_Core_Model_File_Uploader($file);
             $uploader->setAllowedExtensions($this->_getAllowedExtensions());
             $uploader->setAllowRenameFiles(true);
             $uploader->addValidateCallback('size', $this, 'validateMaxSize');
             $result = $uploader->save($uploadDir);
         } catch (Exception $e) {
             Mage::throwException($e->getMessage());
             return $this;
         }
         $filename = $result['file'];
         if ($filename) {
             if ($this->_addWhetherScopeInfo()) {
                 $filename = $this->_prependScopeInfo($filename);
             }
             $this->setValue($filename);
         }
     } else {
         if (is_array($value) && !empty($value['delete'])) {
             // Delete record before it is saved
             $this->delete();
             // Prevent record from being saved, since it was just deleted
             $this->_dataSaveAllowed = false;
         } else {
             $this->unsValue();
         }
     }
     return $this;
 }
コード例 #28
0
 public function uploadAction()
 {
     try {
         $uploader = new Mage_Core_Model_File_Uploader('image');
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->addValidateCallback('catalog_product_image', Mage::helper('catalog/image'), 'validateUploadFile');
         $uploader->setAllowRenameFiles(true);
         $uploader->setFilesDispersion(true);
         $result = $uploader->save(Mage::getSingleton('catalog/product_media_config')->getBaseTmpMediaPath());
         /**
          * Workaround for prototype 1.7 methods "isJSON", "evalJSON" on Windows OS
          */
         $result['tmp_name'] = str_replace(DS, "/", $result['tmp_name']);
         $result['path'] = str_replace(DS, "/", $result['path']);
         $result['url'] = Mage::getSingleton('catalog/product_media_config')->getTmpMediaUrl($result['file']);
         $result['file'] = $result['file'] . '.tmp';
         $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));
 }
コード例 #29
0
 public function saveAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         if (isset($_FILES['image']['name']) && $_FILES['image']['name'] != '') {
             try {
                 $uploader = new Mage_Core_Model_File_Uploader('image');
                 $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                 $uploader->setAllowRenameFiles(true);
                 $uploader->setFilesDispersion(false);
                 $result = $uploader->save(Mage::getBaseDir('media') . DS . 'testimonials' . DS, $_FILES['image']['name']);
             } catch (Exception $e) {
             }
             $data['image'] = 'testimonials/' . $result['file'];
         } elseif (is_array($data['image'])) {
             $data['image'] = $data['image']['value'];
         }
         $model = Mage::getModel('testimonials/testimonials');
         $model->setData($data)->setId($this->getRequest()->getParam('id'));
         try {
             $model->save();
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('testimonials')->__('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('testimonials')->__('Unable to find item to save'));
     $this->_redirect('*/*/');
 }
コード例 #30
-1
ファイル: Image.php プロジェクト: uaudio/magento-filestorage
 /**
  * Save uploaded file and set its name to category
  *
  * @param Varien_Object $object
  */
 public function afterSave($object)
 {
     if (!Mage::helper('uaudio_storage')->isEnabled()) {
         return parent::afterSave($object);
     }
     $value = $object->getData($this->getAttribute()->getName());
     $path = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category' . DS;
     if (is_array($value) && !empty($value['delete'])) {
         $model = Mage::getModel('core/file_storage')->getStorageModel();
         $model->deleteFile($path . $value['value']);
         $object->setData($this->getAttribute()->getName(), '');
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
     }
     try {
         $uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->setAllowRenameFiles(true);
         if (class_exists('Mage_Core_Model_File_Validator_Image')) {
             // added for mage patch SUPEE-7405
             $uploader->addValidateCallback(Mage_Core_Model_File_Validator_Image::NAME, new Mage_Core_Model_File_Validator_Image(), "validate");
         }
         $result = $uploader->save($path);
         $object->setData($this->getAttribute()->getName(), $result['file']);
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
     } catch (Exception $e) {
         if ($e->getCode() != Mage_Core_Model_File_Uploader::TMP_NAME_EMPTY) {
             Mage::logException($e);
         }
         return null;
     }
 }