/** * upload the file and run the import script on it * if a file was already uploaded and the name * of the file is sent in the post request then run the import on this file */ public function importAction() { set_time_limit(0); $baseFileName = ''; $newUpdateFilename = ''; try { //process the upload logic for the csv file if (isset($_FILES['csv']['name']) && $_FILES['csv']['name'] != '') { if (isset($_FILES['csv']['error']) && !empty($_FILES['csv']['error'])) { $message = $this->getUploadCodeMessage($_FILES['csv']['error']); throw new Exception($message, $_FILES['csv']['error']); } $uploader = new Varien_File_Uploader('csv'); $uploader->setAllowedExtensions(array('csv')); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(false); $path = Mage::helper('zitec_dpd/postcode_search')->getPathToDatabaseUpgradeFiles(); if (!is_dir($path)) { mkdir($path, 0777, true); } $uploader->save($path, $_FILES['csv']['name']); $newUpdateFilename = $path . $uploader->getUploadedFileName(); $baseFileName = $uploader->getUploadedFileName(); } // if the no uploads made then check if the path_to_csv field was filed if (empty($newUpdateFilename)) { $baseFileName = $this->getRequest()->getPost('path_to_csv'); if (empty($baseFileName)) { throw new Exception(Mage::helper('core')->__('Nothing to do!! Please upload a file or select an uploaded file.')); } if (isset($baseFileName)) { $path = Mage::helper('zitec_dpd/postcode_search')->getPathToDatabaseUpgradeFiles(); $updateFilename = $path . $baseFileName; if (!is_file($updateFilename)) { throw new Exception(Mage::helper('core')->__('File %s was not found in path media/dpd/postcode_updates', $baseFileName)); } $newUpdateFilename = $updateFilename; } } if (!is_file($newUpdateFilename)) { throw new Exception(Mage::helper('core')->__('File %s was not found in path media/dpd/postcode_updates', $baseFileName)); } } catch (Exception $e) { Mage::getSingleton('core/session')->addError($e->getMessage()); $this->_redirect("zitec_dpd/adminhtml_postcode/updateForm"); return; } // with the filename found, we need to run the database update script // by calling the updateDatabase function of the postcode library try { Mage::helper('zitec_dpd/postcode_search')->updateDatabase($newUpdateFilename); Mage::getSingleton('core/session')->addSuccess(Mage::helper('core')->__('Last updates found on file %s, were installed successfully.', $baseFileName)); } catch (Exception $e) { Mage::getSingleton('core/session')->addError($e->getMessage()); } $this->_redirect("zitec_dpd/adminhtml_postcode/updateForm"); }
public function postAction() { if (!empty($_FILES)) { $type = 'file'; if (isset($_FILES[$type]['name']) && $_FILES[$type]['name'] != '') { try { $uploadsDir = Mage::getBaseDir('upload'); $uploader = new Varien_File_Uploader($type); $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png')); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(true); $path = Mage::getBaseDir('media') . DS . 'upload'; if (!is_dir($path)) { mkdir($path, 0777, true); } $uploader->save($path, $_FILES[$type]['name']); $filename = $uploader->getUploadedFileName(); $md5 = md5($filename); $owner = Mage::getSingleton('customer/session')->getCustomerId() ? Mage::getSingleton('customer/session')->getCustomerId() : Mage::getSingleton('customer/session')->getSessionId(); Mage::getModel('xxx_catalog/upload')->setMd5($md5)->setFilename($filename)->setOwner($owner)->save(); $varienImage = new Varien_Image($uploadsDir . $filename); $width = $varienImage->getOriginalWidth(); $height = $varienImage->getOriginalHeight(); $data = ['id' => $md5, 'width' => $width, 'height' => $height]; echo json_encode($data); die; } catch (Exception $e) { Mage::log($e->getMessage(), null, $this->_logFile); echo json_encode(['error' => $this->__($e->getMessage())]); } } } $this->getResponse()->setRedirect(Mage::getUrl('*/*/index')); }
/** * 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; }
/** * 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; }
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; }
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; }
/** * Save uploaded file and set its name to entity * * @param Goodahead_Etm_Model_Entity $object * @return void */ public function afterSave($object) { parent::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 $this; } $path = Mage::getBaseDir('media') . DS . 'goodahead' . DS . 'etm' . DS . 'images' . DS . $object->getEntityTypeInstance()->getEntityTypeCode() . DS . $this->getAttribute()->getAttributeCode() . DS; try { $uploader = new Varien_File_Uploader($this->getAttribute()->getName()); $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png')); $uploader->setAllowRenameFiles(true); $uploader->setAllowCreateFolders(true); $uploader->setFilesDispersion(true); $uploader->save($path); $object->setData($this->getAttribute()->getName(), $uploader->getUploadedFileName()); $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 $this; } return $this; }
public function importDataAction() { try { if ($this->getRequest()->getPost()) { if (isset($_FILES['import_file']['name']) && $_FILES['import_file']['name'] != '') { $uploaderFile = new Varien_File_Uploader('import_file'); $uploaderFile->setAllowedExtensions(array('csv')); $uploaderFile->setAllowRenameFiles(true); $uploaderFile->setFilesDispersion(false); $uploaderFilePath = Mage::getBaseDir('cache') . DS . 'mgs' . DS . 'brand' . DS . 'import' . DS . 'csv' . DS; $uploaderFile->save($uploaderFilePath, $_FILES['import_file']['name']); $filePath = $uploaderFilePath . $uploaderFile->getUploadedFileName(); $csv = new Varien_File_Csv(); $brands = $csv->getData($filePath); $i = 0; foreach ($brands as $brand) { if ($i > 0) { Mage::helper('brand')->import($brand); } $i++; } $urlRewriteCollection = Mage::getModel('core/url_rewrite')->getCollection()->addFieldToFilter('id_path', 'brand/index/'); foreach ($urlRewriteCollection as $url) { $url->delete(); } $urlRewrite = Mage::getModel('core/url_rewrite')->loadByIdPath('brand/index')->setIdPath('brand/index'); if (Mage::helper('brand')->urlKey() != '') { $urlRewrite->setRequestPath(Mage::helper('brand')->urlKey()); } else { $urlRewrite->setRequestPath('brand'); } $urlRewrite->setTargetPath('brand/index/index'); $urlRewrite->setIsSystem(1); $urlRewrite->save(); $collection = Mage::getModel('brand/brand')->getCollection(); foreach ($collection as $brand) { $urlRewriteCollection = Mage::getModel('core/url_rewrite')->getCollection()->addFieldToFilter('id_path', 'brand/view/' . $brand->getId()); foreach ($urlRewriteCollection as $url) { $url->delete(); } $urlRewrite = Mage::getModel('core/url_rewrite')->loadByIdPath('brand/view/' . $brand->getId())->setIdPath('brand/view/' . $brand->getId()); if (Mage::helper('brand')->urlKey() != '') { $urlRewrite->setRequestPath(Mage::helper('brand')->urlKey() . '/' . $brand->getUrlKey()); } else { $urlRewrite->setRequestPath('brand/' . $brand->getUrlKey()); } $urlRewrite->setTargetPath('brand/index/view/id/' . $brand->getId()); $urlRewrite->setIsSystem(1); $urlRewrite->save(); } Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('brand')->__('All brands were successfully imported.')); $this->_redirect('*/*/index'); } } } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); $this->_redirect('*/*/import'); } }
public function saveAction() { $this->checkFilter(); if ($data = $this->getRequest()->getPost()) { if (isset($_FILES['imagename']['name']) && $_FILES['imagename']['name'] != '') { try { /* Starting upload */ $uploader = new Varien_File_Uploader('imagename'); // 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); $NewName = time() . $_FILES['imagename']['name']; // We set media as the upload dir $path = Mage::getBaseDir('media') . DS . 'images' . DS . 'slider'; // $uploader->save($path, $_FILES['imagename']['name'] ); $uploader->save($path, $NewName); $data['imagename'] = $uploader->getUploadedFileName(); } catch (Exception $e) { } } // end if valid file $model = Mage::getModel('slider/imageslider'); $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('slider')->__('Item was successfully saved')); Mage::getSingleton('adminhtml/session')->setFormData(false); if ($this->getRequest()->getParam('back')) { // die('do back action'); // $this->_redirect('*/*/edit', array('id' => $model->getId())); $this->_redirect('*/*/edit', array('id' => $model->getId())); return; } $this->_redirect($this->_RedirectLink); // $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; } } // end if get post ok Mage::getSingleton('adminhtml/session')->addError(Mage::helper('slider')->__('Unable to find item to save')); $this->_redirect($this->_RedirectLink); // $this->_redirect('*/*/'); }
/** * 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']) { $fieldConfig = $this->getFieldConfig(); /* @var $fieldConfig Varien_Simplexml_Element */ if (empty($fieldConfig->upload_dir)) { Mage::throwException(Mage::helper('catalog')->__('Base directory to upload image file is not specified')); } $uploadDir = (string) $fieldConfig->upload_dir; $el = $fieldConfig->descend('upload_dir'); /** * Add scope info */ if (!empty($el['scope_info'])) { $uploadDir = $this->_appendScopeInfo($uploadDir); } /** * Take root from config */ if (!empty($el['config'])) { $uploadRoot = (string) Mage::getConfig()->getNode((string) $el['config'], $this->getScope(), $this->getScopeId()); $uploadRoot = Mage::getConfig()->substDistroServerVars($uploadRoot); $uploadDir = $uploadRoot . '/' . $uploadDir; } 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()) { /** * Add scope info */ if (!empty($el['scope_info'])) { $filename = $this->_prependScopeInfo($filename); } $this->setValue($filename); } } return $this; }
/** * Save action */ public function saveAction() { if (!($data = $this->getRequest()->getPost('testimonials'))) { $this->_redirect('*/*/'); return; } $model = Mage::getModel('tm_testimonials/data'); if ($id = $this->getRequest()->getParam('testimonial_id')) { $model->load($id); } try { $mediaPath = Mage::getBaseDir('media') . DS . TM_Testimonials_Model_Data::IMAGE_PATH; if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) { try { $uploader = new Varien_File_Uploader('image'); $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png', 'bmp')); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(true); $res = $uploader->save($mediaPath); $data['image'] = $uploader->getUploadedFileName(); } catch (Exception $e) { $this->_getSession()->addError($e->getMessage()); } } if (isset($data['image']) && is_array($data['image'])) { if (!empty($data['image']['delete'])) { @unlink($mediaPath . $data['image']['value']); $data['image'] = null; } else { $data['image'] = $data['image']['value']; } } $model->addData($data); $date = Mage::app()->getLocale()->date($data['date'], Zend_Date::DATE_SHORT, null, false); $model->setDate($date->toString('YYYY-MM-dd HH:mm:ss')); $model->save(); // clear testimonials list block cache after new item was added Mage::app()->cleanCache(array('tm_testimonials_list')); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('testimonials')->__('Testimonial has been saved.')); Mage::getSingleton('adminhtml/session')->setFormData(false); if ($this->getRequest()->getParam('back')) { $this->_redirect('*/*/edit', array('testimonial_id' => $model->getId(), '_current' => true)); return; } $this->_redirect('*/*/'); return; } catch (Exception $e) { $this->_getSession()->addError($e->getMessage()); } $this->_getSession()->setFormData($data); $this->_redirect('*/*/edit', array('testimonial_id' => $this->getRequest()->getParam('testimonial_id'), '_current' => true)); }
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 Varien_File_Uploader($this->getAttribute()->getName()); $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png')); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(true); } catch (Exception $e) { return; } $uploader->save(Mage::getStoreConfig('system/filesystem/media') . '/catalog/category'); if ($uploader->getUploadedFileName()) { $object->setData($this->getAttribute()->getName(), $uploader->getUploadedFileName()); $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName()); } }
public function saveAvatarFile() { $uploadedFile = null; if ($fileData = $this->getAvatarFileData()) { $uploader = new Varien_File_Uploader($this->getAvatarFileData()); $uploader->setFilesDispersion(true); $uploader->setFilenamesCaseSensitivity(false); $uploader->setAllowRenameFiles(true); $uploader->setAllowedExtensions($this->_supportedExtensions); $uploader->save($this->getAvatarBasePath(), $fileData['name']); $uploadedFile = $uploader->getUploadedFileName(); } return $uploadedFile; }
public function saveAction() { if ($this->getRequest()->getPost()) { try { $postData = $this->getRequest()->getPost(); $imageModel = Mage::getModel('aitcg/mask'); if (isset($_FILES['filename']['name']) and file_exists($_FILES['filename']['tmp_name'])) { $uploader = new Varien_File_Uploader('filename'); $uploader->setAllowedExtensions(array('png')); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(false); $path = $imageModel->getImagesPath(); $uploader->save($path, preg_replace('/[^A-Za-z\\d\\.]/', '_', $_FILES['filename']['name'])); $postData['filename'] = $uploader->getUploadedFileName(); } $imageModel->load($this->getRequest()->getParam('imgid'))->setName($postData['name'])->setResize($postData['resize'])->setCategoryId($this->getRequest()->getParam('id')); if (isset($postData['filename'])) { if ($imageModel->getFilename()) { $fullPath = $imageModel->getImagesPath() . $imageModel->getFilename(); @unlink($fullPath); $fullPath = $imageModel->getImagesPath() . 'preview' . DS . $imageModel->getFilename(); @unlink($fullPath); } $imageModel->setFilename($postData['filename']); $thumb = new Varien_Image($imageModel->getImagesPath() . $imageModel->getFilename()); $thumb->open(); $thumb->keepAspectRatio(true); $thumb->keepFrame(true); $thumb->backgroundColor(array(255, 255, 255)); #$thumb->keepTransparency(true); $thumb->resize(135); $thumb->save($imageModel->getImagesPath() . 'preview' . DS . $imageModel->getFilename()); $imageModel->createInvertMask(); } $imageModel->save(); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully saved')); Mage::getSingleton('adminhtml/session')->setImageData(false); $this->_redirect('*/*/', array('id' => $this->getRequest()->getParam('id'))); return; } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); Mage::getSingleton('adminhtml/session')->setImageData($this->getRequest()->getPost()); $this->_redirect('*/*/edit', array('imgid' => $this->getRequest()->getParam('imgid'), 'id' => $this->getRequest()->getParam('id'))); return; } } $this->_redirect('*/*/', array('id' => $this->getRequest()->getParam('id'))); }
/** * action after form submition */ public function applyPostAction() { if ($data = $this->getRequest()->getPost()) { $session = $this->_getSession(); $model = Mage::getModel('zeon_jobs/application'); try { if (!empty($data)) { $model->addData($data); $session->setFormData($data); } if (isset($_FILES['upload_resume']['name']) && $_FILES['upload_resume']['name'] != '') { $uploader = new Varien_File_Uploader('upload_resume'); $uploader->setAllowedExtensions(explode(',', Mage::helper('zeon_jobs')->getAllowedFileExtensions())); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(false); $path = Mage::getBaseDir('media') . DS . 'resumes' . DS; $_FILES['upload_resume']['name'] = str_replace(' ', '-', $_FILES['upload_resume']['name']); $uploader->save($path, $_FILES['upload_resume']['name']); $model->setUploadResume($uploader->getUploadedFileName()); } $model->save(); $session->addSuccess(Mage::helper('zeon_jobs')->__('Your application has been submitted. Thank you for contacting us.')); $translate = Mage::getSingleton('core/translate'); $translate->setTranslateInline(false); /*To send email*/ $dataObject = new Varien_Object(); $dataObject->setData($data); //Send Email Notification to Admin & User if (!$model->sendNotificationEmail($dataObject)) { throw new Exception('Email notification has not been sent.'); } $translate->setTranslateInline(true); // Redirect to a success page, at the moment it goes back to the job list. $this->_redirect('careers'); return; } catch (Exception $e) { $session->addError($e->getMessage()); $session->getFormData($data); $this->_redirect('careers'); return; } } }
public function uploadAction() { Mage::log($_FILES); if ($data = $this->getRequest()->getPost()) { $type = 'file'; if (isset($_FILES[$type]['name']) && $_FILES[$type]['name'] != '') { try { $uploader = new Varien_File_Uploader($type); //$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png')); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(true); $path = Mage::getBaseDir('media') . DS . 'uploads' . DS; $uploader->save($path, $_FILES[$type]['name']); $filename = $uploader->getUploadedFileName(); } catch (Exception $e) { } } echo $filename; } }
public function beforeSave($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') . '/prolabel/default/'; try { $uploader = new Varien_File_Uploader($this->getAttribute()->getName()); $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png')); $uploader->setAllowRenameFiles(true); $uploader->save($path); $object->setData($this->getAttribute()->getName(), $uploader->getUploadedFileName()); $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName()); } catch (Exception $e) { return; } }
protected function _uploadFiles($files, $fileName) { $path = Mage::getSingleton('prescriptionpayment/prescriptionpayment')->getUploaderPath(); $fTypesArr = Mage::getSingleton('prescriptionpayment/prescriptionpayment')->getAllowedFilesTypesAsArray(); try { $uploader = new Varien_File_Uploader($files); // Allows only files defined in backend $uploader->setAllowedExtensions($fTypesArr); // Can create uploader folder $uploader->setAllowCreateFolders(true); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(true); $uploader->save($path, $fileName); $targetFilename = $uploader->getUploadedFileName(); // Add file to model Mage::getSingleton('prescriptionpayment/prescriptionpayment')->addUploadedFile($targetFilename); Mage::log("\n___" . 'File (' . $targetFilename . ') uploaded!' . "___\n"); } catch (Exception $e) { Mage::log('ERROR: ' . $e->getCode() . ' : ' . $e->getMessage()); } }
/** * 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); $uploader->save($path); $object->setData($this->getAttribute()->getName(), $uploader->getUploadedFileName()); $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName()); } catch (Exception $e) { Mage::logException($e); /** @TODO ??? */ return; } }
protected function _afterSave() { if (is_string($this->getGuiData())) { $this->setGuiData(unserialize($this->getGuiData())); } Mage::getModel('dataflow/profile_history')->setProfileId($this->getId())->setActionCode($this->getOrigData('profile_id') ? 'update' : 'create')->save(); if (isset($_FILES['file_1']['tmp_name']) || isset($_FILES['file_2']['tmp_name']) || isset($_FILES['file_3']['tmp_name'])) { for ($index = 0; $index < 3; $index++) { if ($file = $_FILES['file_' . ($index + 1)]['tmp_name']) { $uploader = new Varien_File_Uploader('file_' . ($index + 1)); $uploader->setAllowedExtensions(array('csv', 'xml')); $path = Mage::app()->getConfig()->getTempVarDir() . '/import/'; $uploader->save($path); if ($uploadFile = $uploader->getUploadedFileName()) { $newFilename = 'import-' . date('YmdHis') . '-' . ($index + 1) . '_' . $uploadFile; rename($path . $uploadFile, $path . $newFilename); } } } } parent::_afterSave(); }
/** * Function to upload product image * * @param int $filename * @param array $filesDataArray * @return string */ public function uploadImage($filename, $filesDataArray) { /** * Create instance for uploader */ $uploader = new Varien_File_Uploader($filename); /** * SEt allowed extensions */ $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png')); $uploader->addValidateCallback('catalog_product_image', Mage::helper('catalog/image'), 'validateUploadFile'); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(false); /** * Initilize path */ $path = Mage::getBaseDir('media') . DS . 'tmp' . DS . 'catalog' . DS . 'product' . DS; $uploader->save($path, $filesDataArray[$filename]['name']); /** * Return path */ return $path . $uploader->getUploadedFileName(); }
public function uploadFile($name) { try { $exAr = explode(',', str_replace('.', '', Mage::getStoreConfig('vc_giftwrap/general/image_extension_allow'))); $uploader = new Varien_File_Uploader($name); // Any extention would work //$uploader->setAllowedExtensions(Mage::helper('vc_giftwrap')->getExtensionAr()); //$uploader->setAllowedExtensions(array('png','gif','jpg','jpeg')); $uploader->setAllowedExtensions($exAr); $uploader->setAllowRenameFiles(false); $uploader->setFilesDispersion(false); // We set media as the upload dir $path = $this->getImagePath(); $fileName = $_FILES[$name]['name']; if (file_exists($path . '/' . $fileName)) { $fileName = $this->renameFile($path, $fileName); } $uploader->save($path, $fileName); } catch (Exception $e) { throw new Exception($e->getMessage()); } return $uploader->getUploadedFileName(); }
public function beforeSave($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') . '/catalog/category/'; try { $uploader = new Varien_File_Uploader($this->getAttribute()->getName()); $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png')); $uploader->setAllowRenameFiles(true); $uploader->save($path); $object->setData($this->getAttribute()->getName(), $uploader->getUploadedFileName()); $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName()); } catch (Exception $e) { return; } /*if( $_FILES['image']['error'] > 0 ) { return $this; } $path = Mage::getBaseDir('media') . '/catalog/category' . '/' . $this->getScope(); if ('default' != $this->getScope()) { $path .= '/' . $this->getScopeId(); } die($path); $uploader = new Varien_File_Uploader('image'); $uploader->save($path); $object->setImage($uploader->getUploadedFileName()); return $this;*/ }
/** * Export attribute value to entity model * * @param Mage_Core_Model_Abstract $entity * @param array|string $value * @return Mage_Eav_Model_Attribute_Data_File */ public function compactValue($value) { if ($this->getIsAjaxRequest()) { return $this; } $attribute = $this->getAttribute(); $original = $this->getEntity()->getData($attribute->getAttributeCode()); $toDelete = false; if ($original) { if (!$attribute->getIsRequired() && !empty($value['delete'])) { $toDelete = true; } if (!empty($value['tmp_name'])) { $toDelete = true; } } $path = Mage::getBaseDir('media') . DS . $attribute->getEntity()->getEntityTypeCode(); // unlink entity file if ($toDelete) { $this->getEntity()->setData($attribute->getAttributeCode(), ''); $file = $path . $original; $ioFile = new Varien_Io_File(); if ($ioFile->fileExists($file)) { $ioFile->rm($file); } } if (!empty($value['tmp_name'])) { try { $uploader = new Varien_File_Uploader($value); $uploader->setFilesDispersion(true); $uploader->setFilenamesCaseSensitivity(false); $uploader->setAllowRenameFiles(true); $uploader->save($path, $value['name']); $fileName = $uploader->getUploadedFileName(); $this->getEntity()->setData($attribute->getAttributeCode(), $fileName); } catch (Exception $e) { Mage::logException($e); } } return $this; }
public function saveAction() { $this->loadLayout(); // do this first $this->getLayout()->getBlock('head')->setTitle($this->__('Popup')); // then this works if ($data = $this->getRequest()->getPost()) { $data = $this->_filterDateTime($data, array('from_date', 'to_date')); $model = Mage::getModel('magebird_popup/popup'); $id = $this->getRequest()->getParam('id'); if ($id) { $model->load($id); } if (isset($_FILES['image']['name']) && $_FILES['image']['name'] != '') { try { /* Starting upload */ $uploader = new Varien_File_Uploader('image'); // Any extention would work $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png')); $uploader->setAllowRenameFiles(false); $uploader->setFilesDispersion(false); // We set media as the upload dir $path = Mage::getBaseDir('media') . DS . 'popup' . DS; $uploader->setAllowCreateFolders(true); $uploader->save($path, $_FILES['image']['name']); $uploadedFile = $uploader->getUploadedFileName(); } catch (Exception $e) { $uploadedFile = null; $this->_getSession()->addException($e, Mage::helper('magebird_popup')->__('Error uploading image. Please try again later.')); } $data['image'] = "popup/" . $uploadedFile; } else { if (isset($data['image']['delete']) && $data['image']['delete'] == 1) { $data["image"] = ""; //if id then image is already stored inside $data['image'] } elseif (!$id && $data["popup_type"] == 1) { if (!$data['image']['value']) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('magebird_popup')->__('Please choose your image or select "Custom Content" in "Popup Content Type" field.')); } $data['image'] = $data['image']['value']; } else { unset($data["image"]); } } $model->setData($data); Mage::getModel('magebird_popup/popup')->setFormData($data); try { if ($id) { $model->setId($id); } $model->save(); if (!$model->getId()) { Mage::throwException(Mage::helper('magebird_popup')->__('Error saving popup')); } Mage::getModel('magebird_popup/popup')->parsePopupContent($model->getId()); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('magebird_popup')->__('Popup was successfully saved.')); Mage::getSingleton('adminhtml/session')->setFormData(false); // The following line decides if it is a "save" or "save and continue" 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('magebird_popup')->__('No data found to save')); $this->_redirect('*/*/'); }
public function saveBulkUploadFiles($filesDataArray) { $csvFilePath = $homeFolder = $imageFilePath = ''; /** Get Customer Id */ $sellerId = Mage::getSingleton('customer/session')->getCustomer()->getId(); /** * Getting Current Time */ $currentDateTime = date("Ymd_His", Mage::getModel('core/date')->timestamp(time())); foreach ($filesDataArray as $key => $value) { /** * Initilize file name */ $filename = $key; /** * Upload csv file */ if ($key == 'bulk-product-upload-csv-file' && isset($filesDataArray[$filename]['name']) && file_exists($filesDataArray[$filename]['tmp_name'])) { $csvFilePath = ''; $csvFilePath = array(); $uploader = new Varien_File_Uploader($filename); $uploader->setAllowedExtensions(array('csv')); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(false); $path = Mage::getBaseDir('media') . DS . 'marketplace' . DS . 'bulk' . DS . 'product' . DS . 'csv' . DS; $uploader->save($path, 'seller_' . $sellerId . '_date_' . $currentDateTime . '.csv'); $csvFilePath = $path . $uploader->getUploadedFileName(); } /** * Upload csv image */ if ($key == 'bulk-product-upload-image-file' && isset($filesDataArray[$filename]['name']) && file_exists($filesDataArray[$filename]['tmp_name'])) { $uploader = new Varien_File_Uploader($filename); $uploader->setAllowedExtensions(array('zip')); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(false); $path = Mage::getBaseDir('media') . DS . 'marketplace' . DS . 'bulk' . DS . 'product' . DS . 'image' . DS; /** * Uploader save */ $uploader->save($path, 'seller_' . $sellerId . '_date_' . $currentDateTime . '.zip'); $imageFilePath = $path . $uploader->getUploadedFileName(); $ZipFileName = $imageFilePath; $homeFolder = Mage::getBaseDir('media') . DS . 'marketplace' . DS . 'bulk' . DS . 'product' . DS . 'image' . DS . 'seller_' . $sellerId . '_date_' . $currentDateTime; /** * New Varien File */ $file = new Varien_Io_File(); /** * Make Directory */ $file->mkdir($homeFolder); Mage::helper('marketplace/product')->exportZipFile($ZipFileName, $homeFolder); } } /** * Conver csv file path */ $productData = Mage::helper('marketplace/product')->convertCsvFileToUploadArray($csvFilePath); $this->bulkproductuploadfuncationality($imageFilePath, $productData, $homeFolder, $csvFilePath); return true; }
public static function uploadImage($sizeWidth = null, $sizeHeight = null) { $image_path = Mage::getBaseDir('media') . DS . 'customerattribute/image'; $image_file_name = ""; if (isset($_FILES['image']['name']) && $_FILES['image']['name'] != '') { try { /* Starting upload */ $uploader = new Varien_File_Uploader('image'); // Any extention would work $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png')); $uploader->setAllowRenameFiles(false); $uploader->setFilesDispersion(true); $result = $uploader->save($image_path, $uploader->getCorrectFileName($_FILES['image']['name'])); $image_file_name = substr(strrchr($uploader->getUploadedFileName(), "/"), 1); //resize image if ($result) { $image = new Varien_Image($image_path + '/' + $image_file_name); if ($sizeWidth != null) { $image->resize($sizeWidth, $sizeHeight); $image->save(); } } } catch (Exception $e) { Mage::logException($e); } } return $image_file_name; }
/** * Save action */ public function saveAction() { $redirectBack = $this->getRequest()->getParam('back', false); if ($data = $this->getRequest()->getPost()) { $id = $this->getRequest()->getParam('id'); $model = $this->_initManufacturer(); if (!$model->getId() && $id) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('zeon_manufacturer')->__('This manufacturer no longer exists.')); $this->_redirect('*/*/'); return; } $manufacturerName = $model->getManufacturerName($data['manufacturer'], Mage::app()->getStore()->getId()); $identifier = $data['identifier'] ? $data['identifier'] : $manufacturerName; $data['identifier'] = Mage::getModel('zeon_manufacturer/url')->formatUrlKey($identifier); // save manufacturer logo and banner $fieldName = array(); $fieldName[0] = 'manufacturer_logo'; $fieldName[1] = 'manufacturer_banner'; if ($count = count($_FILES)) { for ($i = 0; $i < $count; $i++) { if (isset($_FILES[$fieldName[$i]]['name']) && $_FILES[$fieldName[$i]]['tmp_name'] != '') { $uploader = new Varien_File_Uploader($fieldName[$i]); $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png')); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(false); $path = Mage::getBaseDir('media') . DS . 'manufacturer' . DS; $_FILES[$fieldName[$i]]['name'] = str_replace(' ', '-', $_FILES[$fieldName[$i]]['name']); $uploader->save($path, $_FILES[$fieldName[$i]]['name']); $data[$fieldName[$i]] = $_FILES[$fieldName[$i]]['name']; if ($_FILES['manufacturer_logo']['name'] && $_FILES['manufacturer_logo']['tmp_name'] != '') { $model->setManufacturerLogo($uploader->getUploadedFileName()); } else { $model->setManufacturerBanner($uploader->getUploadedFileName()); } } else { if (isset($data[$fieldName[$i]]['delete']) && $data[$fieldName[$i]]['delete'] == 1) { $data[$fieldName[$i]] = ''; } else { unset($data[$fieldName[$i]]); } } } } // save model try { if (!empty($data)) { $model->addData($data); Mage::getSingleton('adminhtml/session')->setFormData($data); } $model->save(); Mage::getSingleton('adminhtml/session')->setFormData(false); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('zeon_manufacturer')->__('The manufacturer has been saved.')); } catch (Mage_Core_Exception $e) { $this->_getSession()->addError($e->getMessage()); $redirectBack = true; } catch (Exception $e) { $this->_getSession()->addError(Mage::helper('zeon_manufacturer')->__('Unable to save the manufacturer.')); $redirectBack = true; Mage::logException($e); } if ($redirectBack) { $this->_redirect('*/*/edit', array('id' => $model->getId())); return; } } $this->_redirect('*/*/'); }
/** * save data menu */ public function saveAction() { $result = array(); if ($data = $this->getRequest()->getPost()) { $data['store_id'] = !isset($data['store_switcher']) ? 0 : $data['store_switcher']; $store_id = $data['store_id']; $megamenu = isset($data['megamenu']) ? $data['megamenu'] : array(); if (!$megamenu) { if ($store_id) { $result['redirect'] = $this->getUrl('*/*/index', array('store_id' => $store_id)); } else { $result['redirect'] = $this->getUrl('*/*/index'); } Mage::getSingleton('adminhtml/session')->addWarning(Mage::helper('ves_megamenu')->__('Please input menu title and choose other menu parent (not ROOT)')); $this->getResponse()->setBody('<script type="text/javascript">parent.window.location.href = "' . $result['redirect'] . '";</script>'); return; } $check_exist = false; if (!$this->getRequest()->getParam('id') && (!isset($megamenu['title']) || !$megamenu['title']) && (!$megamenu['parent_id'] || $megamenu['parent_id'] == 1)) { $check_exist = Mage::getModel('ves_megamenu/megamenu')->checkExistMenuRoot(1, $store_id); } if ($check_exist) { if ($store_id) { $result['redirect'] = $this->getUrl('*/*/index', array('store_id' => $store_id)); } else { $result['redirect'] = $this->getUrl('*/*/index'); } Mage::getSingleton('adminhtml/session')->addWarning(Mage::helper('ves_megamenu')->__('Please input menu title and choose other menu parent (not ROOT)')); $this->getResponse()->setBody('<script type="text/javascript">parent.window.location.href = "' . $result['redirect'] . '";</script>'); return; } $save_mode = $this->getRequest()->getParam('save_mode'); $id = 0; if ($id = $this->getRequest()->getParam('id')) { $model = Mage::getModel('ves_megamenu/megamenu')->load($id); } else { $model = Mage::getModel('ves_megamenu/megamenu')->load(null); } $image = $model->getImage(); 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); $uploader->setFilesDispersion(true); $path = Mage::getBaseDir('media') . DS . 'ves_megamenu'; $uploader->save($path, $_FILES['image']['name']); } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); return; } $image = 'ves_megamenu' . $uploader->getUploadedFileName(); } if (isset($data['image']['delete']) && $data['image']['delete'] == 1) { $path = Mage::getBaseDir('media') . DS . $image; if ($image && file_exists($path)) { @unlink($path); } $image = ''; } $data['megamenu']['image'] = $image; switch ($data['megamenu']['type']) { case 'category': $data['megamenu']['item'] = isset($data['category']) ? $data['category'] : 0; break; case 'cms_page': $data['megamenu']['item'] = isset($data['cms_page']) ? $data['cms_page'] : 0; break; case 'product': $data['megamenu']['item'] = isset($data['megamenu']['product']) ? $data['megamenu']['product'] : 0; break; case 'static_block': $data['megamenu']['item'] = isset($data['static_block']) ? $data['static_block'] : 0; break; } if (!isset($data['megamenu']['parent_id']) || empty($data['megamenu']['parent_id'])) { $data['megamenu']['parent_id'] = 1; } if ($data['megamenu']['parent_id']) { $level = Mage::getModel('ves_megamenu/megamenu')->load($data['megamenu']['parent_id'])->getLevel(); $level += 1; $data['megamenu']['level'] = $level; } else { $root = Mage::getModel('ves_megamenu/megamenu')->getCollection()->addFieldToFilter('parent_id', 1)->addStoreFilter($data['store_id']); if (count($root)) { $firstitem = $root->getFirstItem(); if ($firstitem->getId() != $id) { Mage::getSingleton('adminhtml/session')->addError('Only one root Menu on Store'); if ($save_mode == "save-edit") { $result['redirect'] = $this->getUrl('*/*/edit', array('id' => $this->getRequest()->getParam('id'), 'store_id' => $store_id)); $this->getResponse()->setBody('<script type="text/javascript">parent.window.location.href = "' . $result['redirect'] . '";</script>'); } else { $result['redirect'] = $this->getUrl('*/*/index', array('store_id' => $store_id)); $this->getResponse()->setBody('<script type="text/javascript">parent.window.location.href = "' . $result['redirect'] . '";</script>'); } return; } } $data['megamenu']['level'] = 0; } $data['megamenu']['stores'] = !empty($data['store_id']) ? array($data['store_id']) : array(0); $data['megamenu']['position'] = isset($data['megamenu']['position']) ? $data['megamenu']['position'] : 0; $data['megamenu']['target'] = isset($data['megamenu']['target']) ? $data['megamenu']['target'] : ""; $data_megamenu = array("title" => $data['megamenu']['title'], "description" => $data['megamenu']['description'], "level" => $data['megamenu']['level'], "show_title" => $data['megamenu']['show_title'], "published" => $data['megamenu']['published'], "is_group" => $data['megamenu']['is_group'], "image" => $data['megamenu']['image'], "widget_id" => $data['megamenu']['widget_id'], "submenu_content" => $data['megamenu']['submenu_content'], "submenu_colum_width" => $data['megamenu']['submenu_colum_width'], "colums" => $data['megamenu']['colums'], "menu_class" => $data['megamenu']['menu_class'], "type_submenu" => $data['megamenu']['type_submenu'], "content_text" => $data['megamenu']['content_text'], "menu_icon_class" => isset($data['megamenu']['menu_icon_class']) ? $data['megamenu']['menu_icon_class'] : "", "type" => $data['megamenu']['type'], "item" => $data['megamenu']['item'], "url" => $data['megamenu']['url'], "width" => $data['megamenu']['width'], "position" => $data['megamenu']['position'], "parent_id" => $data['megamenu']['parent_id'], "store_id" => $data['store_id'], "target" => $data['megamenu']['target'], "stores" => $data['megamenu']['stores']); $model->setData($data_megamenu); if ($this->getRequest()->getParam('id')) { $model->setId($this->getRequest()->getParam('id')); } try { $model->save(); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('ves_megamenu')->__('Megamenu was successfully saved')); if ($save_mode == "save-edit") { $result['redirect'] = $this->getUrl('*/*/edit', array('id' => $model->getId(), 'store_id' => $store_id)); } else { $result['redirect'] = $this->getUrl('*/*/index', array('store_id' => $store_id)); } } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); $result['redirect'] = $this->getUrl('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); if ($save_mode == "save-edit") { $result['redirect'] = $this->getUrl('*/*/edit', array('id' => $model->getId(), 'store_id' => $store_id)); } else { $result['redirect'] = $this->getUrl('*/*/index', array('store_id' => $store_id)); } } } else { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('ves_megamenu')->__('Could not find anymegamenu to save')); if ($save_mode == "save-edit") { $result['redirect'] = $this->getUrl('*/*/edit', array('id' => $model->getId(), 'store_id' => $store_id)); } else { $result['redirect'] = $this->getUrl('*/*/index', array('store_id' => $store_id)); } } $this->getResponse()->setBody('<script type="text/javascript">parent.window.location.href = "' . $result['redirect'] . '";</script>'); }
public function importPostAction() { if ($this->getRequest()->isPost()) { try { $uploader = new Varien_File_Uploader('file'); $uploader->setAllowedExtensions(array('zip')); $uploader->setAllowCreateFolders(true); $uploader->setAllowRenameFiles(false); $uploader->setFilesDispersion(false); $uploader->save('var/slider/'); $file = $uploader->getUploadedFileName(); $filePath = Mage::getBaseDir('var') . DS . 'slider' . DS . $file; $fileInfo = pathinfo($filePath); switch ($fileInfo['extension']) { case 'zip': $slider = $this->_processZipImport($filePath); break; default: throw new Exception(Mage::helper('revslider')->__('Only zip file supported.')); } if ($slider->getId()) { $helper = Mage::helper('revslider'); /* @var $helper AM_RevSlider_Helper_Data */ $this->_getSession()->addSuccess(Mage::helper('revslider')->__('Importing slider successful. <a href="%s" target="_blank">Edit</a> or <a href="%s" target="_blank">Preview</a> now', $this->getUrl('*/*/edit', array('id' => $slider->getId())), $helper->getFrontendUrl('revslider/index/preview', array('id' => $slider->getId())))); } @unlink($filePath); } catch (Exception $e) { $this->_getSession()->addError($e->getMessage()); } } $this->_redirect('*/*/import'); }