/** * 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 saveAction() { if ($this->getRequest()->getPost()) { $req = $this->getRequest(); $redirectBack = $req->getParam('back', false); $id = $req->getParam('id'); try { $stores = $req->getParam('stores'); if (is_array($stores)) { $stores = join(',', $stores); } $icons = $req->getParam('icon'); $icon = isset($icons['value']) ? $icons['value'] : null; if (isset($icons['delete']) && $icons['delete'] == 1) { $file = Mage::getBaseDir('media') . $icon; if (file_exists($file) && is_writable($file)) { unlink($file); } else { $this->_getSession()->addWarning($this->__("Icon file does not exist or cannot be deleted.")); } $icon = null; } else { if (isset($_FILES['icon']['tmp_name']) && !empty($_FILES['icon']['tmp_name'])) { try { $uploader = new Varien_File_Uploader('icon'); $target = $this->getIconsDir(); $result = $uploader->setAllowCreateFolders(true)->setAllowedExtensions(array('png'))->addValidateCallback('size', Mage::helper('ustorelocator/protected'), 'validateIconSize')->save($target); $icon = Mage::helper('ustorelocator')->getIconDirPrefix() . DS . $result['file']; } catch (Exception $e) { $this->_getSession()->addWarning($e->getMessage()); } } } $udVendor = $req->getParam('udropship_vendor'); if (empty($udVendor) && $udVendor !== 0) { $udVendor = null; } $model = Mage::getModel('ustorelocator/location')->setId($req->getParam('id'))->setTitle($req->getParam('title'))->setAddress($req->getParam('address'))->setNotes($req->getParam('notes'))->setLongitude($req->getParam('longitude'))->setLatitude($req->getParam('latitude'))->setAddressDisplay($req->getParam('address_display'))->setNotes($req->getParam('notes'))->setWebsiteUrl($req->getParam('website_url'))->setPhone($req->getParam('phone'))->setUdropshipVendor($udVendor)->setCountry($req->getParam('country'))->setProductTypes($req->getParam('product_types'))->setIsFeatured($req->getParam('is_featured'))->setUseLabel($req->getParam('use_label'))->setZoom($req->getParam('zoom') ? $req->getParam('zoom') : 15)->setStores($stores)->setIcon($icon); $model->save(); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Store location was successfully saved')); if ($redirectBack) { if ($model->getId()) { $id = $model->getId(); } $this->_redirect('*/*/edit', array('id' => $id)); } else { $this->_redirect('*/*/'); } return; } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); $this->_redirect('*/*/edit', array('id' => $id)); return; } } $this->_redirect('*/*/'); }
public function saveAction() { $model = Mage::getModel('testimonial/testimonial'); if ($data = $this->getRequest()->getPost()) { if (isset($_FILES['avatar']['name']) && $_FILES['avatar']['name'] != '') { try { $path = Mage::getBaseDir() . DS . 'media/magebuzz/avatar' . DS; $fname = $_FILES['avatar']['name']; $fname = str_replace(' ', '_', $fname); $uploader = new Varien_File_Uploader('avatar'); $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif')); $uploader->setAllowCreateFolders(true); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(false); $destFile = $path . $fname; $fname = $model->getNewFileName($destFile); $uploader->save($path, $fname); } catch (Exception $e) { echo 'Error Message: ' . $e->getMessage(); } //this way the name is saved in DB $data['avatar'] = $_FILES['avatar']['name']; } else { unset($data['avatar']); } $model->setData($data)->setId($this->getRequest()->getParam('id')); if (isset($_FILES['avatar']['name']) && $_FILES['avatar']['name'] != '') { $model->setAvatarName($fname); $model->setAvatarPath($path); } try { if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) { $model->setCreatedTime(now())->setUpdateTime(now()); } else { $model->setUpdateTime(now()); } $model->save(); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('testimonial')->__('Item was successfully saved')); Mage::getSingleton('adminhtml/session')->setFormData(false); if ($this->getRequest()->getParam('back')) { $this->_redirect('*/*/edit', array('id' => $model->getId())); return; } $this->_redirect('*/*/'); return; } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); Mage::getSingleton('adminhtml/session')->setFormData($data); $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); return; } } Mage::getSingleton('adminhtml/session')->addError(Mage::helper('testimonial')->__('Unable to find item to save')); $this->_redirect('*/*/'); }
/** * Upload and import the given bankdata file */ public function saveAction() { if ($this->getRequest()->isPost()) { $country = $this->getRequest()->getPost('country_id', false); if (!$country || !isset($_FILES['upload_file']['name']) || !file_exists($_FILES['upload_file']['tmp_name'])) { $this->_getSession()->addError($this->_getDebitHelper()->__('Please fill in all required fields.')); $this->_redirect('*/*/upload'); return; } try { $path = Mage::getBaseDir('var') . DS; $filename = 'debitpayment_upload_file.csv'; $uploader = new Varien_File_Uploader('upload_file'); $uploader->setAllowedExtensions(array('csv')); $uploader->setAllowCreateFolders(true); $uploader->setAllowRenameFiles(false); $uploader->setFilesDispersion(false); $uploader->save($path, $filename); $file = new Varien_Io_File(); $file->open(array('path' => $path)); $file->streamOpen($filename, 'r'); $i = 1; $import = array(); while (($line = $file->streamReadCsv()) !== false) { if ($i == 1) { $i++; continue; } // Check if routing number already exists $swiftCode = trim($line[2]); if (array_key_exists($swiftCode, $import) || empty($swiftCode)) { continue; } // Add bank to array $import[$swiftCode] = array('routing_number' => trim($line[0]), 'swift_code' => $swiftCode, 'bank_name' => trim($line[1])); } $file->streamClose(); $importData = array($country => $import); /* @var $model Itabs_Debit_Model_Import_Bankdata */ $model = Mage::getModel('debit/import_bankdata'); $model->importData($importData); unlink($path . $filename); $this->_getSession()->addSuccess($this->_getDebitHelper()->__('Upload successful!')); } catch (Exception $e) { $this->_getSession()->addError($e->getMessage()); $this->_redirect('*/*/upload'); return; } } $this->_redirect('*/*'); }
public function saveAction() { if ($this->getRequest()->getPost()) { try { $postData = $this->getRequest()->getPost(); $helloModel = Mage::getModel('hello/posts'); if (!empty($_FILES['image']['name'])) { try { $path = Mage::getBaseDir('media') . DS . 'posts'; if (!file_exists($path)) { mkdir($path, 0777, true); } $uploader = new Varien_File_Uploader('image'); $uploader->setAllowedExtensions(array('jpg', 'png', 'gif', 'jpeg')); $uploader->setAllowRenameFiles(TRUE); $uploader->setAllowCreateFolders(TRUE); $uploader->setFilesDispersion(false); unlink(Mage::getBaseDir('media') . DS . 'posts' . DS . $_FILES['image']['name']); $uploader->save($path, $_FILES['image']['name']); $postData['image'] = $_FILES['image']['name']; } catch (Exception $e) { var_dump($e); die("fail"); } } else { if (isset($postData['image']['delete']) && $postData['image']['delete'] == 1) { unlink(Mage::getBaseDir('media') . DS . 'posts' . DS . $postData['image']['value']); $postData['image'] = ''; } else { unset($postData['image']); } } if ($this->getRequest()->getParam('id') <= 0) { $helloModel->setCreatedTime(Mage::getSingleton('core/date')->gmtDate()); } $helloModel->addData($postData)->setUpdateTime(Mage::getSingleton('core/date')->gmtDate())->setId($this->getRequest()->getParam('id'))->save(); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully saved')); Mage::getSingleton('adminhtml/session')->setNewsData(false); $this->_redirect('*/*/'); return; } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); Mage::getSingleton('adminhtml/session')->setNewsData($this->getRequest()->getPost()); $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); return; } } $this->_redirect('*/*/'); }
public function save() { $model = Mage::getModel('testimonial/testimonial'); $post = $this->getRequest()->getPost(); if ($post) { //Upload avatar if (isset($_FILES['avatar']['name']) && $_FILES['avatar']['name'] != '') { try { $path = Mage::getBaseDir() . DS . 'media/magebuzz/avatar' . DS; $fname = $_FILES['avatar']['name']; $fname = str_replace(' ', '_', $fname); $uploader = new Varien_File_Uploader('avatar'); $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif')); $uploader->setAllowCreateFolders(true); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(false); $destFile = $path . $fname; $fname = $model->getNewFileName($destFile); $uploader->save($path, $fname); } catch (Exception $e) { echo 'Error Message: ' . $e->getMessage(); } } //Save to datatabase try { $model->setData($post); $model->setAvatarName($fname); $model->setAvatarPath($path); $now = Mage::getModel('core/date')->timestamp(now()); $model->setCreatedTime(date('Y-m-d H:i:s', $now)); if (Mage::getStoreConfig('testimonial/testimonial_options/approve_testimonial', Mage::app()->getStore()) == true) { $model->setData('status', self::STATUS_PENDING); } else { $model->setData('status', self::STATUS_ENABLED); } $model->save(); //Send mail after customer post testimonial if (Mage::getStoreConfig('testimonial/email_configuration/send_email_after_post_testimonial', Mage::app()->getStore()) == "1") { $to = array('email' => $post['email'], 'name' => $post['name']); $this->sendemailAction($to, $templateConfigPath = self::XML_PATH_EMAIL_SELECT_TEMPLATE_AFTER_POST); } $this->_redirect('*/index/thankmessage'); } catch (Exception $e) { echo $e->getMessage(); } } else { $this->_redirect(''); } }
public function massImportAction() { if ($data = $this->getRequest()->getPost()) { try { if (isset($_FILES['file']['name']) && $_FILES['file']['name'] != '') { try { $path = Mage::getBaseDir('media') . DS . 'import' . DS . 'coupon' . DS; // . date('ymd').'_pe_loyalty_voucher.csv'; //$path = Mage::getBaseDir().DS.'csv'.DS; //desitnation directory $fname = $_FILES['file']['name']; //file name $fullname = $path . $fname; $uploader = new Varien_File_Uploader('file'); //load class $uploader->setAllowedExtensions(array('CSV', 'csv')); //Allowed extension for file $uploader->setAllowCreateFolders(true); //for creating the directory if not exists $uploader->setAllowRenameFiles(false); $uploader->setFilesDispersion(false); $uploader->save($path, $fname); //save the Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('coupon')->__("File has been uploaded successfully.")); $this->_redirect('*/*/import'); return; } catch (Exception $e) { $fileType = "Invalid file format"; } } if ($fileType == "Invalid file format") { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('foundation')->__($fname . " Invalid file format")); $this->_redirect('*/*/'); return; } $result = Mage::getSingleton('coupon/coupon')->import($data['file']); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('coupon')->__('%s coupon(s) imported successfully.<br/> %s coupon(s) were already exists.', $result['count'], $result['countNotImpt'])); Mage::getSingleton('adminhtml/session')->setFormData(false); $this->_redirect('*/*/'); } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); Mage::getSingleton('adminhtml/session')->setFormData($data); $this->_redirect('*/*/import'); } } }
public function produploadAction() { if (isset($_FILES['docname']['name']) && $_FILES['docname']['name'] != '') { try { $path = Mage::getBaseDir() . DS . 'var' . DS . 'import' . DS; //desitnation directory $fname = $_FILES['docname']['name']; //file name $uDate = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $updatedDate = $uDate->format('d-m-Y H:i:s'); $filePath = Mage::getBaseDir() . DS . 'var' . DS . 'import' . DS . $fname; if (!is_file($filePath)) { $uploader = new Varien_File_Uploader('docname'); //load class $uploader->setAllowedExtensions(array('csv')); //Allowed extension for file $uploader->setAllowCreateFolders(true); //for creating the directory if not exists $uploader->setAllowRenameFiles(false); //if true, uploaded file's name will be changed, if file with the same name already exists directory. $uploader->setFilesDispersion(false); $uploader->save($path, $fname); //save the file on the specified path $newstatus = 'New'; $pupload = Mage::getModel('productupload/productupload'); $pupload->setFile($fname); $pupload->setUpdatedTime($updatedDate); $pupload->setStatus($newstatus); $pupload->save(); $message = $this->__('Product csv file successfully uploaded.'); Mage::getSingleton('core/session')->addSuccess($message); $this->_redirect('*/'); } else { $message = $this->__('Product csv file already exit.'); Mage::getSingleton('core/session')->addError($message); $this->_redirect('*/'); } } catch (Exception $e) { $message = $this->__('Disallowed file type.'); Mage::getSingleton('core/session')->addError($message); $this->_redirect('*/'); } } $this->renderLayout(); }
/** * Save the link attachment * * @param Rootd_Link_Model_Node The link model. * * @return Rootd_Link_Adminhtml_LinkController */ protected function _saveAttachment(Rootd_Link_Model_Node $model) { $helper = Mage::helper('link'); try { if (isset($_FILES['target_file']) && !empty($_FILES['target_file']['name'])) { $file = $_FILES['target_file']['name']; $path = $helper->generateAttachmentPath($file, true); $uploader = new Varien_File_Uploader('target_file'); $uploader->setAllowCreateFolders(true); $uploader->setAllowRenameFiles(false); $uploader->setFilesDispersion(false); $uploader->save(dirname($path), $file); $model->setTargetFile($helper->generateAttachmentPath($file, false))->setSaveAttachmentFlag(true); } } catch (Exception $error) { Mage::getSingleton('adminhtml/session')->addNotice($helper->__("Failed to upload attachment: {$error->getMessage()}")); } return $this; }
public function salvarImagem($_files) { foreach (array_keys($_files) as $key) { if (strpos($key, 'imagem') === 0) { if (isset($_FILES[$key]['name']) && $_FILES[$key]['name'] != '') { try { $path = Mage::getBaseDir() . DS . 'media' . DS . 'cores' . DS; //desitnation directory $short_path = 'cores' . DS; $fname = $_FILES[$key]['name']; //file name while (file_exists($path . $fname)) { $fname = 'file_' . $fname; } $fname = str_replace(' ', '', $fname); $file_index = str_replace('upload_file', '', $key); $name_file = $params['name_file' . $file_index]; if ($name_file == '') { $name_file = $fname; } $uploader = new Varien_File_Uploader($key); //load class $uploader->setAllowedExtensions(array('jpg', 'png', 'gif')); //Allowed extension for file $uploader->setAllowCreateFolders(true); //for creating the directory if not exists $uploader->setAllowRenameFiles(false); //if true, uploaded file's name will be changed, if file with the same name already exists directory. $uploader->setFilesDispersion(false); $uploader->save($path, utf8_decode($fname)); //save the file on the specified path return $fname; } catch (Exception $e) { echo 'Error Message: ' . $e->getMessage(); exit; } } } } return false; }
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()); } }
/** * Upload File Action */ public function uploadAction() { if (!empty($_FILES)) { try { $uploader = new Varien_File_Uploader("file"); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(false); $uploader->setAllowCreateFolders(true); $path = $this->_getUploadDir(); /* @var $helper Pimgento_Core_Helper_Data */ $helper = Mage::helper('pimgento_core'); $uploader->setAllowedExtensions($helper->getAllowedExtensions()); $uploadSaveResult = $uploader->save($path, $_FILES['file']['name']); $result = $uploadSaveResult['file']; } catch (Exception $e) { $result = array("error" => $e->getMessage(), "errorCode" => $e->getCode(), "status" => "error"); } /* @var $helper Mage_Core_Helper_Data */ $coreHelper = Mage::helper('core'); $this->getResponse()->setBody($coreHelper->jsonEncode($result)); } }
/** * upload file and get the uploaded name * * @access public * @param string $input * @param string $destinationFolder * @param array $data * @return string * @author Ultimate Module Creator */ protected function _uploadAndGetName($input, $destinationFolder, $data) { try { if (isset($data[$input]['delete'])) { return ''; } else { $uploader = new Varien_File_Uploader($input); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(true); $uploader->setAllowCreateFolders(true); $result = $uploader->save($destinationFolder); return $result['file']; } } catch (Exception $e) { if ($e->getCode() != Varien_File_Uploader::TMP_NAME_EMPTY) { throw $e; } else { if (isset($data[$input]['value'])) { return $data[$input]['value']; } } } return ''; }
/** * @param string $attributeCode * @param string $type * @return bool */ protected static function handleUpload($attributeCode, $type) { if (!isset($_FILES)) { return false; } $adapter = new Zend_File_Transfer_Adapter_Http(); if ($adapter->isUploaded('typecms_' . $attributeCode . '_')) { if (!$adapter->isValid('typecms_' . $attributeCode . '_')) { Mage::throwException(Mage::helper('typecms')->__('Uploaded ' . $type . ' is invalid')); } $upload = new Varien_File_Uploader('typecms[' . $attributeCode . ']'); $upload->setAllowCreateFolders(true); if ($type == 'image') { $upload->setAllowedExtensions(array('jpg', 'gif', 'png')); } $upload->setAllowRenameFiles(true); $upload->setFilesDispersion(false); try { if ($upload->save(Mage::helper('typecms')->getBaseImageDir())) { return $upload->getUploadedFileName(); } } catch (Exception $e) { Mage::throwException('Uploaded ' . $type . ' is invalid'); } } return false; }
public function manualInstallUploadAction() { $this->_prepare(); $turnOnModule = false; if (!$this->_getModule()->getValue() && $this->_getLicense()->isUninstalled()) { $turnOnModule = true; } if (isset($_FILES['license_file']['name']) && $_FILES['license_file']['name'] != '') { try { $path = Mage::getBaseDir('var'); $fname = $_FILES['license_file']['name']; $uploader = new Varien_File_Uploader('license_file'); $uploader->setAllowedExtensions(array('sql', 'php')); $uploader->setAllowCreateFolders(true); $uploader->setAllowRenameFiles(false); $uploader->setFilesDispersion(false); $uploader->save($path, $fname); switch (pathinfo($fname, PATHINFO_EXTENSION)) { case 'php': copy($path . DS . $fname, $path . DS . 'ait_install' . DS . $this->_getLicense()->getPlatform()->getPlatformId() . DS . $fname); break; case 'sql': default: $sql = file_get_contents($path . DS . $fname); $writeConnection = Mage::getSingleton('core/resource')->getConnection('core_write'); $writeConnection->query($sql); break; } unlink($path . DS . $fname); $this->_getModule()->updateStatuses(); if (!$this->_getLicense()->isUninstalled()) { if ($turnOnModule) { $data = array(); foreach ($this->tool()->platform()->getModuleKeysForced() as $module => $value) { /* @var $module Aitoc_Aitsys_Model_Module */ $isCurrent = $module === $this->_getModule()->getKey(); $data[$module] = $isCurrent ? true : $value; } $aitsysModel = new Aitoc_Aitsys_Model_Aitsys(); $errors = $aitsysModel->saveData($data, array(), true); if ($errors) { foreach ($errors as $error) { Mage::getSingleton('adminhtml/session')->addError($this->__($error)); } } } Mage::getSingleton('adminhtml/session')->addSuccess($this->__('License of %s module has been installed.', $this->_getModule()->getLabel())); } else { Mage::getSingleton('adminhtml/session')->addError($this->__('Unknown error. Please retry the operation again. If installation fails, contact support department.')); } } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); } } else { Mage::getSingleton('adminhtml/session')->addError($this->__('No file uploaded.')); } $this->_redirect('*'); }
/** * Upload and create preview image * * @throws Mage_Core_Exception * @param string $scope the request key for file * @return bool */ public function uploadPreviewImage($scope) { $adapter = new Zend_File_Transfer_Adapter_Http(); if (!$adapter->isUploaded($scope)) { return false; } if (!$adapter->isValid($scope)) { Mage::throwException(Mage::helper('Mage_Core_Helper_Data')->__('Uploaded image is not valid')); } $upload = new Varien_File_Uploader($scope); $upload->setAllowCreateFolders(true); $upload->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png', 'xbm', 'wbmp')); $upload->setAllowRenameFiles(true); $upload->setFilesDispersion(false); if (!$upload->save($this->getImagePathOrigin())) { Mage::throwException(Mage::helper('Mage_Core_Helper_Data')->__('Image can not be saved.')); } $fileName = $this->getImagePathOrigin() . DS . $upload->getUploadedFileName(); $this->removePreviewImage()->createPreviewImage($fileName); $this->_getIoFile()->rm($fileName); return true; }
/** * @function save type Form csv data * * * * * */ public function typeFormSurvery() { try { $path = Mage::getBaseDir() . DS . 'survey_csv'; if (!is_dir()) { mkdir($path); } $uploader = new Varien_File_Uploader('csv_file'); $uploader->setAllowedExtensions(array('csv')); $uploader->setAllowCreateFolders(true); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(false); $savedPath = $uploader->save($path, $fname); $savedFilePath = $savedPath['path'] . DS . $savedPath['file']; $csv = new Varien_File_Csv(); $data = $csv->getData($savedFilePath); unlink($savedFilePath); $surveryModel = Mage::getModel('survey/survey'); $hasColumnNameRow = $surveryModel->getCollection()->setPageSize(1); //zend_debug::dump($data);exit; if (count($hasColumnNameRow) == 0) { //$surveryModel->setData('completed', strtotime(trim($value[1]))); //$surveryModel->setData('token', trim($value[4])); $surveryModel->setData('q1', $data[0][1]); $surveryModel->setData('q2', $data[0][3]); // $surveryModel->setData('q3', $data[0][11]); $surveryModel->setData('q4', $data[0][2]); $surveryModel->setData('q5', $data[0][5]); $surveryModel->setData('q6', $data[0][4]); $surveryModel->setData('q7', $data[0][7]); $surveryModel->setData('q8', $data[0][6]); //$surveryModel->setData('q9', $data[0][17]); $surveryModel->save(); $surveryModel->unsetData(); } unset($data[0]); foreach ($data as $key => $value) { $surveryModel->setData('token', $value[9]); $date = trim($value[12]); $date = str_replace('/', '-', $date); $surveryModel->setData('completed', date('Y-m-d', strtotime($date))); $surveryModel->setData('q1', $value[1]); $surveryModel->setData('q2', $value[3]); //$surveryModel->setData('q3', $value[11]); $surveryModel->setData('q4', $value[2]); $surveryModel->setData('q5', $value[5]); $surveryModel->setData('q6', $value[4]); $surveryModel->setData('q7', $value[7]); $surveryModel->setData('q8', $value[6]); //$surveryModel->setData('q9', $value[17]); $surveryModel->save(); $surveryModel->unsetData(); } Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Survey Uploaded Successfully.. ')); Mage::getSingleton('adminhtml/session')->setCrmData(false); $this->_redirect('*/*/'); return; } catch (exception $e) { Mage::getSingleton('adminhtml/session')->addError('There is some error.. '); Mage::getSingleton('adminhtml/session')->setCrmData($this->getRequest()->getPost()); $this->_redirect('*/*/'); return; } }
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'); }
protected function x0e() { $x1c = $this->_helper->getTmpFileBaseDir(); $x1d = ''; $x1e = ''; if (!empty($x1f["data_import_file"]["name"])) { if (file_exists($x1f["data_import_file"]["tmp_name"])) { try { $x20 = new Varien_File_Uploader("data_import_file"); $x20->setAllowedExtensions(array('xml')); $x20->setAllowCreateFolders(true); $x20->setAllowRenameFiles(false); $x20->setFilesDispersion(false); $x20->save($x1c, $x1f["data_import_file"]["name"]); $x1e = $x1c . $x1f["data_import_file"]["name"]; } catch (Exception $x13) { Mage::getSingleton("adminhtml/session")->addError($this->_helper->__("An error occurred during upload of file %s", $x1f["data_import_file"]["name"]) . "<br/>" . $this->_helper->__("Exception: %s", $x13->getMessage())); } } } else { $x1e = $this->_hc->getPresetFilepath($this->getRequest()->getParam("preset_name"), $this->getRequest()->getParam("package")); } if (!empty($x1e)) { return $x1e; } else { return ''; } }
public function importPostAction() { if ($this->getRequest()->isPost()) { try { $uploader = new Varien_File_Uploader('file'); $uploader->setAllowedExtensions(array('rs')); $uploader->setAllowCreateFolders(true); $uploader->setAllowRenameFiles(false); $uploader->setFilesDispersion(false); $uploader->save('var/slider/'); $file = $uploader->getUploadedFileName(); $path = Mage::getBaseDir('var') . DS . 'slider' . DS . $file; $data = unserialize(file_get_contents($path)); if (!isset($data['title']) && !isset($data['layout'])) { throw new Exception(Mage::helper('revslider')->__('Data invalid.')); } $json = Mage::helper('core'); $model = Mage::getModel('revslider/slider'); $model->setData(array('title' => $data['title'], 'status' => 1, 'params' => $json->jsonEncode($data))); $model->save(); if (isset($data['slides']) && is_array($data['slides'])) { foreach ($data['slides'] as $index => $slideData) { $layers = isset($slideData['layers']) ? $slideData['layers'] : array(); if (isset($slideData['layers'])) { unset($slideData['layers']); } $slide = Mage::getModel('revslider/slide'); $slide->setData(array('slider_id' => $model->getId(), 'slide_order' => $index + 1, 'params' => $json->jsonEncode($slideData), 'layers' => $json->jsonEncode($layers))); $slide->save(); } } $this->_getSession()->addSuccess(Mage::helper('revslider')->__('Slider import successfully.')); } catch (Exception $e) { $this->_getSession()->addError($e->getMessage()); } } $this->_redirect('*/*/import'); }
/** * Upload image and return uploaded image file name or false * * @throws Mage_Core_Exception * @param string $scope the request key for file * @return bool|string */ public function uploadImage($scope) { $adapter = new Zend_File_Transfer_Adapter_Http(); $adapter->addValidator('ImageSize', true, $this->_imageSize); $adapter->addValidator('Size', true, self::MAX_FILE_SIZE); if ($adapter->isUploaded($scope)) { // validate image if (!$adapter->isValid($scope)) { Mage::throwException(Mage::helper('hello')->__('Uploaded image is not valid')); } $upload = new Varien_File_Uploader($scope); $upload->setAllowCreateFolders(true); $upload->setAllowedExtensions($this->_allowedExtensions); $upload->setAllowRenameFiles(true); $upload->setFilesDispersion(false); if ($upload->save($this->getBaseDir())) { return $upload->getUploadedFileName(); } } return false; }
public function UploadImage($fieldId, $fileName = null) { try { $path = Mage::helper('iwd_productvideo')->GetMediaImageDir(); $uploader = new Varien_File_Uploader($fieldId); $uploader->setAllowedExtensions($this->allowImageFormats); $uploader->setAllowCreateFolders(true); $uploader->setAllowRenameFiles(false); $uploader->setFilesDispersion(false); $uploader->save($path, $fileName); } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('iwd_productvideo')->__($e->getMessage())); return false; } return true; }
public function uploadAction() { if (!$this->_validateFormKey()) { $this->_getCoreSession()->addError('非法表单提交'); return $this->_redirect('sns/show/index'); } $errors = array(); $fields = $this->getRequest()->getPost(); if ($fields) { if (isset($_FILES['photo']) && $_FILES['photo']['name'] != '') { $product = Mage::getModel('catalog/product')->load($fields['productid']); require_once "lib/Varien/File/Uploader.php"; $path = Mage::getBaseDir() . DS . 'media' . DS . 'show' . DS . $product->getSku() . DS . $this->_getSession()->getCustomerId(); //desitnation directory $fname = $_FILES['photo']['name']; //file name $uploader = new Varien_File_Uploader('photo'); //load class $uploader->setAllowedExtensions(array('jpg', 'png', 'gif')); //Allowed extension for file $uploader->setAllowCreateFolders(true); //for creating the directory if not exists $uploader->setAllowRenameFiles(false); //if true, uploaded file's name will be changed, if file with the same name already exists directory. $uploader->setFilesDispersion(false); $error = $uploader->save($path, $fname); //save the file on the specified path if ($error['error']) { $errors[] = $error['error']; } $path2 = Mage::getUrl() . 'media' . DS . 'show' . DS . $product->getSku() . DS . $this->_getSession()->getCustomerId() . DS . $fname; $userimage = Mage::getModel('blog/userimages'); $userimage->setData('title', $fields['name']); $userimage->setData('product_id', $fields['productid']); $userimage->setData('filename', $path . $fname); $userimage->setData('description', ''); $userimage->setData('data1', $product->getSku()); $userimage->setData('data2', $fields['email']); $userimage->setData('data3', $fields['telephone']); $userimage->setData('data4', $this->_getSession()->getCustomerId()); $userimage->setData('data5', $path2); try { $userimage->save(); if (count($errors)) { foreach ($errors as $message) { $this->_getCoreSession()->addError($message); } } else { $this->_getCoreSession()->addSuccess($this->__('图片上传成功')); } $this->_redirect('sns/show/success'); return; } catch (Mage_Core_Exception $e) { $this->_getCoreSession()->addError($e->getMessage()); } catch (Exception $e) { $this->_getCoreSession()->addException($e, $this->__('保存信息遇到错误')); } } } $this->_redirect('sns/show/success'); return; }
/** * Save action * * @return void */ public function saveAction() { $event = Mage::getModel('enterprise_catalogevent/event')->setStoreId($this->getRequest()->getParam('store', 0)); /* @var $event Enterprise_CatalogEvent_Model_Event */ if ($eventId = $this->getRequest()->getParam('id', false)) { $event->load($eventId); } else { $event->setCategoryId($this->getRequest()->getParam('category_id')); } $postData = $this->_filterPostData($this->getRequest()->getPost()); if (!isset($postData['catalogevent'])) { $this->_getSession()->addError(Mage::helper('enterprise_catalogevent')->__('An error occurred while saving this event.')); $this->_redirect('*/*/edit', array('_current' => true)); return; } $data = new Varien_Object($postData['catalogevent']); $event->setDisplayState($data->getDisplayState())->setStoreDateStart($data->getDateStart())->setStoreDateEnd($data->getDateEnd())->setSortOrder($data->getSortOrder()); $isUploaded = true; try { $uploader = new Varien_File_Uploader('image'); $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png')); $uploader->setAllowRenameFiles(true); $uploader->setAllowCreateFolders(true); $uploader->setFilesDispersion(false); } catch (Exception $e) { $isUploaded = false; } $validateResult = $event->validate(); if ($validateResult !== true) { foreach ($validateResult as $errorMessage) { $this->_getSession()->addError($errorMessage); } $this->_getSession()->setEventData($event->getData()); $this->_redirect('*/*/edit', array('_current' => true)); return; } try { if ($data->getData('image/is_default')) { $event->setImage(null); } elseif ($data->getData('image/delete')) { $event->setImage(''); } elseif ($isUploaded) { try { $event->setImage($uploader); } catch (Exception $e) { Mage::throwException(Mage::helper('enterprise_catalogevent')->__('Image was not uploaded.')); } } $event->save(); $this->_getSession()->addSuccess(Mage::helper('enterprise_catalogevent')->__('Event has been saved.')); if ($this->getRequest()->getParam('_continue')) { $this->_redirect('*/*/edit', array('_current' => true, 'id' => $event->getId())); } else { $this->_redirect('*/*/'); } } catch (Exception $e) { $this->_getSession()->addError($e->getMessage()); $this->_getSession()->setEventData($event->getData()); $this->_redirect('*/*/edit', array('_current' => true)); } }
public function uploadImage($scope) { // create an instance of class Zend_File_Transfer_Adapter_Http // and add validator $adapter = new Zend_File_Transfer_Adapter_Http(); $adapter->addValidator('ImageSize', true, $this->_imageSize); $adapter->addValidator('Size', true, self::MAX_FILE_SIZE); // if image can be uploaded if ($adapter->isUploaded($scope)) { //validate image if (!$adapter->isValid($scope)) { Mage::throwException(Mage::helper('ab_adverboard')->__('Uploaded image is not valid')); } // upload image $upload = new Varien_File_Uploader($scope); $upload->setAllowCreateFolders(true); $upload->setAllowedExtensions($this->_allowedExtensions); $upload->setAllowRenameFiles(false); $upload->setFilesDispersion(false); if ($upload->save($this->getBaseDir(), $_FILES['image']['name'])) { return $upload->getUploadedFileName(); } } return false; }
public function saveAction() { if ($data = $this->getRequest()->getPost()) { if (isset($_FILES['categoryicon']['name']) && $_FILES['categoryicon']['name'] != '') { try { /* Starting upload */ $uploader = new Varien_File_Uploader('categoryicon'); // 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); $uploader->setAllowCreateFolders(true); // We set media as the upload dir $path = Mage::getBaseDir('media') . DS . 'homepage' . DS; $uploader->save($path, $_FILES['categoryicon']['name']); } catch (Exception $e) { } //this way the name is saved in DB $data['categoryicon'] = $_FILES['categoryicon']['name']; } else { if (isset($data['categoryicon']['delete']) && $data['categoryicon']['delete'] == 1) { $data['image_main'] = ''; } else { unset($data['categoryicon']); } } /////////////////////////////////////////////////// //////////////////////////By Ravi ///////////////////////// if (isset($_FILES['bannerimage']['name']) && $_FILES['bannerimage']['name'] != '') { try { /* Starting upload */ $uploader = new Varien_File_Uploader('bannerimage'); // 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); //To create a folder automatically $uploader->setAllowCreateFolders(true); // We set media as the upload dir //We add any folder inside media folder like shown below $path = Mage::getBaseDir('media') . DS . 'homepage' . DS; $uploader->save($path, $_FILES['bannerimage']['name']); } catch (Exception $e) { } //this way the name is saved in DB $data['bannerimage'] = $_FILES['bannerimage']['name']; } else { if (isset($data['bannerimage']['delete']) && $data['bannerimage']['delete'] == 1) { $data['image_main'] = ''; } else { unset($data['bannerimage']); } } /////////////////////////////////////////////////// //////////////////////////By Ravi///////////////// ///////////////////////////////////////////////// ///////////////////////// By Ravi ////////////////////////// foreach ($data as $key => $value) { if (is_array($value)) { $data[$key] = implode(',', $this->getRequest()->getParam($key)); } } ////////////////////////////////////////////////// $model = Mage::getModel('homepage/homepage'); $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('homepage')->__('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('homepage')->__('Unable to find item to save')); $this->_redirect('*/*/'); }
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('*/*/'); }
/** * Save attribute file for given object * * @param Mage_Core_Model_Abstract $object * @return BL_FileAttributes_Model_Attribute_Backend_File */ protected function _saveAttributeFile($object) { $helper = Mage::helper('fileattributes'); $attribute = $this->getAttribute(); $value = $object->getData($attribute->getName()); $label = $attribute->getFrontendLabel(); $maxFileSize = $this->getUploadMaxFilesize(); /* Using enableHeaderCheck() on Zend "mime-type" file validators seems to be not useful, as it checks the type retrieved from Zend_File_Transfer, and Zend_File_Transfer_Adapter_Abstract::_detectMimeType() seems to not be using a different detection than those validators, actually it does just return "application/octet-stream" by default */ //$allowMimeHeaderCheck = Mage::helper('fileattributes/config')->getAllowMimeHeaderCheck(); if (is_array($value) && !empty($value['delete'])) { // Just reset value, files deletion is accessible from elsewhere if ($object->getId()) { $this->_saveObjectAttributeValue($object, ''); } else { $this->_pendingSaveObject = $object; $this->_pendingSaveValue = ''; } return $this; } $upload = new Zend_File_Transfer_Adapter_Http(); $file = $attribute->getName(); try { $origData = $object->getOrigData(); $origFile = isset($origData[$file]) ? $origData[$file] : null; $newFile = is_array($value) ? $value['value'] : $value; if (!$upload->isUploaded($file) && (!$attribute->getIsRequired() || $newFile == $origFile)) { // No need to go further return $this; } $fileInfo = $upload->getFileInfo($file); $fileInfo = $fileInfo[$file]; $fileInfo['title'] = $fileInfo['name']; } catch (Exception $e) { // Upload error if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] < $maxFileSize) { $size = Mage::helper('fileattributes')->getFileSizeForDisplay($maxFileSize, 2); Mage::throwException($helper->__('The file you uploaded for "%s" attribute is larger than the %s allowed by server', $label, $size)); } else { Mage::throwException($helper->__('An error occured during file upload for "%s" attribute', $label)); } } $config = Mage::helper('fileattributes/config')->getAttributeConfiguration($attribute->getId()); // Validation for MIME types if (isset($config['allowed_mime_types']) && is_array($validate = $config['allowed_mime_types'])) { $upload->addValidator('MimeType', false, array_keys($validate)); //$upload->getValidator('MimeType')->enableHeaderCheck($allowMimeHeaderCheck); } elseif (isset($config['forbidden_mime_types']) && is_array($validate = $config['forbidden_mime_types'])) { $upload->addValidator('ExcludeMimeType', false, array_keys($validate)); //$upload->getValidator('ExcludeMimeType')->enableHeaderCheck($allowMimeHeaderCheck); } // Validation for image-only flag if (isset($config['image_only']) && $config['image_only']) { $upload->addValidator('IsImage', false); //$upload->getValidator('IsImage')->enableHeaderCheck($allowMimeHeaderCheck); } // Validation for image dimensions $validate = array(); if ($config['image_min_width'] > 0) { $validate['minwidth'] = $config['image_min_width']; } if ($config['image_max_width'] > 0) { $validate['maxwidth'] = $config['image_max_width']; } if ($config['image_min_height'] > 0) { $validate['minheight'] = $config['image_min_height']; } if ($config['image_max_height'] > 0) { $validate['maxheight'] = $config['image_max_height']; } if (count($validate) > 0) { $upload->addValidator('ImageSize', false, $validate); } // Validation for file extensions if (isset($config['allowed_file_extensions']) && is_array($validate = $config['allowed_file_extensions'])) { $upload->addValidator('Extension', false, $validate); } elseif (isset($config['forbidden_file_extensions']) && is_array($validate = $config['forbidden_file_extensions'])) { $upload->addValidator('ExcludeExtension', false, $validate); } // Validation for maximum filesize (take the smallest between config and server ones) $validate = $config['file_max_size'] > 0 ? min($config['file_max_size'], $maxFileSize) : $maxFileSize; $upload->addValidator('FilesSize', false, array('max' => $validate)); // Let's upload (if possible) ! if ($upload->isUploaded($file) && $upload->isValid($file)) { try { $uploader = new Varien_File_Uploader($attribute->getName()); $uploader->setAllowCreateFolders(true)->setAllowRenameFiles(true)->setFilesDispersion(false); if (!$uploader->save($this->getTargetDir())) { Mage::throwException($helper->__('File "%s" upload failed for "%s" attribute', $fileInfo['name'], $label)); } if ($object->getId()) { $this->_saveObjectAttributeValue($object, $uploader->getUploadedFileName()); } else { $this->_pendingSaveObject = $object; $this->_pendingSaveValue = $uploader->getUploadedFileName(); } } catch (Exception $e) { Mage::throwException($helper->__('An error occured during file "%s" upload for "%s" attribute : "%s"', $fileInfo['name'], $label, $e->getMessage())); } } elseif (($errors = $upload->getErrors()) && ($errors = $this->_parseValidatorErrors($errors, $fileInfo, $label)) && count($errors) > 0) { // Known upload error(s) Mage::throwException(implode("<br />", $errors)); } else { // Unknown or not handled upload error Mage::throwException($helper->__('You must upload a valid file for "%s" attribute', $label)); } }
public function saveAction() { $model = Mage::getModel('testimonial/testimonial'); if ($data = $this->getRequest()->getPost()) { if (isset($_FILES['avatar']['name']) && $_FILES['avatar']['name'] != '') { try { $path = Mage::getBaseDir() . DS . 'media/magentothem/avatar' . DS; $fname = $_FILES['avatar']['name']; $fname = str_replace(' ', '', $fname); $fname = preg_replace('/[^a-zA-Z0-9]/', '', $fname); $uploader = new Varien_File_Uploader('avatar'); $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif')); $uploader->setAllowCreateFolders(true); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(false); $destFile = $path . $fname; $fname = $model->getNewFileName($destFile); $uploader->save($path, $fname); } catch (Exception $e) { echo 'Error Message: ' . $e->getMessage(); } //this way the name is saved in DB $data['avatar'] = $_FILES['avatar']['name']; } else { unset($data['avatar']); } $current_testimonial = Mage::getModel('testimonial/testimonial')->load($this->getRequest()->getParam('id')); $current_status = $current_testimonial->getStatus(); $updated_status = $data['status']; if (Mage::getStoreConfig('testimonial/email_configuration/send_email_after_approve_testimonial', Mage::app()->getStore()) == "1" and ($current_status == "3" and $updated_status == "1")) { $to = array('email' => $this->_getTestimonial()->load($this->getRequest()->getParam('id'))->getEmail(), 'name' => $this->_getTestimonial()->load($this->getRequest()->getParam('id'))->getName()); $this->sendemailAction($to, $templateConfigPath = self::XML_PATH_EMAIL_SELECT_TEMPLATE_AFTER_APPROVE, $this->getRequest()->getParam('id')); Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Admin has just sent the email to customer for approving their testimonials')); } $model->setData($data)->setId($this->getRequest()->getParam('id')); if (isset($_FILES['avatar']['name']) && $_FILES['avatar']['name'] != '') { $model->setAvatarName($fname); $model->setAvatarPath($path); } try { if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) { $model->setCreatedTime(now())->setUpdateTime(now()); } else { $model->setUpdateTime(now()); } $model->save(); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('testimonial')->__('Item was successfully saved')); Mage::getSingleton('adminhtml/session')->setFormData(false); if ($this->getRequest()->getParam('back')) { $this->_redirect('*/*/edit', array('id' => $model->getId())); return; } $this->_redirect('*/*/'); return; } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); Mage::getSingleton('adminhtml/session')->setFormData($data); $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); return; } } Mage::getSingleton('adminhtml/session')->addError(Mage::helper('testimonial')->__('Unable to find item to save')); $this->_redirect('*/*/'); }
public function loadpricekidsAction() { if (isset($_FILES['pricekids']['name']) && $_FILES['pricekids']['name'] != '') { try { $path = Mage::getBaseDir() . DS . 'media' . DS . 'prices' . DS . 'kids'; //desitnation directory $fname = $_FILES['pricekids']['name']; //file name $uploader = new Varien_File_Uploader('pricekids'); //load class $uploader->setAllowedExtensions(array('xls')); //Allowed extension for file $uploader->setAllowCreateFolders(true); //for creating the directory if not exists $uploader->setAllowRenameFiles(false); //if true, uploaded file's name will be changed, if file with the same name already exists directory. $uploader->setFilesDispersion(false); $uploader->save($path, 'file.xls'); //save the file on the specified path $url = Mage::getModel('adminhtml/url')->getUrl('web/adminhtml_web/success'); $this->_redirectUrl($url); } catch (Exception $e) { echo 'Error Message: ' . $e->getMessage(); } } }