当前位置: 首页>>代码示例>>PHP>>正文


PHP Varien_File_Uploader::getCorrectFileName方法代码示例

本文整理汇总了PHP中Varien_File_Uploader::getCorrectFileName方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_File_Uploader::getCorrectFileName方法的具体用法?PHP Varien_File_Uploader::getCorrectFileName怎么用?PHP Varien_File_Uploader::getCorrectFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Varien_File_Uploader的用法示例。


在下文中一共展示了Varien_File_Uploader::getCorrectFileName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: saveAction

 public function saveAction()
 {
     //        var_dump($this->getRequest()->getPost());exit;
     $path = Mage::getBaseDir('media') . DS . 'amlabel' . DS;
     if ($data = $this->getRequest()->getPost()) {
         /*
                     if(isset($_FILES['image']['name'])) {
                         die;
                     }*/
         $model = Mage::getModel('productdlabel/dlabel');
         $id = $this->getRequest()->getParam('id');
         if ($id) {
             $model->load($id);
         }
         $model->setData($data);
         Mage::getSingleton('adminhtml/session')->setFormData($data);
         try {
             if ($id) {
                 $model->setId($id);
             }
             //                var_dump($_FILES['image']);exit;
             $uploader = new Varien_File_Uploader('image');
             $uploader->setFilesDispersion(false);
             $uploader->setAllowRenameFiles(false);
             $uploader->setAllowedExtensions(array('png', 'gif', 'jpg', 'jpeg'));
             $name = $uploader->getCorrectFileName($_FILES['image']['name']);
             $uploader->save($path, $name);
             $model->setData('image', $name);
             $model->save();
             if (!$model->getId()) {
                 Mage::throwException(Mage::helper('productdlabel')->__('Error saving label'));
             }
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('productdlabel')->__('Label 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('productdlabel')->__('No data found to save'));
     $this->_redirect('*/*/');
 }
开发者ID:hientruong90,项目名称:ce_magento,代码行数:53,代码来源:DlabelController.php

示例2: saveAction

 public function saveAction()
 {
     if ($postData = $this->getRequest()->getPost()) {
         $model = Mage::getSingleton($this->posttype_model);
         if ($id = $this->getRequest()->getParam($this->posttype_id, null)) {
             $model->setData($this->posttype_id, $id);
         }
         try {
             $model->setData($this->posttype_name, $this->getRequest()->getParam($this->posttype_name, null));
             $swatch_options = array();
             $post_options = $this->getRequest()->getParam($this->posttype_options, array());
             foreach ($post_options as $key => $option) {
                 $image_id = $this->posttype_options . '_' . $key;
                 // set id if already exists
                 if (intval($key) > 0) {
                     $option['id'] = $key;
                 } elseif (isset($_FILES[$image_id]['name'])) {
                     $uploader = new Varien_File_Uploader($image_id);
                     $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                     $uploader->setAllowRenameFiles(false);
                     $uploader->setFilesDispersion(false);
                     $path = $this->check_path(Mage::getBaseDir('media') . DS . 'catalog' . DS . 'swatches');
                     $image_name = $uploader->getCorrectFileName($_FILES[$image_id]['name']);
                     $uploader->save($path, $image_name);
                     $image_url = 'catalog/swatches/' . $image_name;
                     $this->resize_image($path . DS . $image_name);
                     $option['image'] = $image_url;
                 }
                 $swatch_options[] = $option;
             }
             $model->setData($this->posttype_options, $swatch_options);
             $model->save();
             Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Your changes have been saved.'));
             if ($this->getRequest()->getParam('back')) {
                 $this->_redirect('*/*/edit', array($this->posttype_id => $model->getData($this->posttype_id)));
             } else {
                 $this->_redirect('*/*/');
             }
             return;
         } catch (Mage_Core_Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
         }
         Mage::getSingleton('adminhtml/session')->setData($this->posttype_data, $postData);
         $this->_redirectReferer();
     }
     $this->_redirect('*/*/');
 }
开发者ID:BBFMedia,项目名称:Ip_Swatches,代码行数:49,代码来源:SwatchController.php

示例3: getExportData

 public function getExportData($entityType, $collectionItem)
 {
     // Set return array
     $returnArray = array();
     $this->_writeArray =& $returnArray['webformscrf'];
     if (!$this->fieldLoadingRequired('webformscrf')) {
         return $returnArray;
     }
     // Fetch fields to export
     if ($entityType == Xtento_OrderExport_Model_Export::ENTITY_CUSTOMER) {
         $customer = Mage::getModel('customer/customer')->load($collectionItem->getObject()->getId());
     } else {
         $order = $collectionItem->getOrder();
         $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
         if (!$customer || !$customer->getId()) {
             return $returnArray;
         }
     }
     try {
         $webformId = Mage::getStoreConfig('webformscrf/registration/form', $customer->getStoreId());
         $group = Mage::getModel('customer/group')->load($customer->getGroupId());
         if ($group->getWebformId()) {
             $webformId = $group->getWebformId();
         }
         $collection = Mage::getModel('webforms/results')->getCollection()->addFilter('webform_id', $webformId)->addFilter('customer_id', $customer->getEntityId());
         $collection->getSelect()->order('created_time desc')->limit('1');
         $collection->load();
         if ($collection->count() > 0) {
             $result = $collection->getFirstItem();
             foreach ($result->getField() as $field_id => $value) {
                 $field = Mage::getModel('webforms/fields')->load($field_id);
                 switch ($field->getType()) {
                     case 'file':
                     case 'image':
                         $value = Varien_File_Uploader::getCorrectFileName($value);
                         $this->writeValue('field_' . $field_id . '_url', $result->getDownloadLink($field_id, $value));
                         break;
                 }
                 $this->writeValue('field_' . $field_id, $value);
                 if ($field->getCode()) {
                     $this->writeValue($field->getCode(), $value);
                 }
             }
         }
     } catch (Exception $e) {
     }
     // Done
     return $returnArray;
 }
开发者ID:AleksNesh,项目名称:pandora,代码行数:49,代码来源:MageMeWebFormsCrf.php

示例4: editAction

 /**
  * This method will set “editing mode” if an ID was specified.
  * On the contrary, it will be set “creating mode” and an empty brand entity ready to be populated.
  */
 public function editAction()
 {
     $brand = Mage::getModel('boolfly_brand/brand');
     if ($brandId = $this->getRequest()->getParam('id', false)) {
         $brand->load($brandId);
         if ($brand->getId() < 1) {
             $this->_getSession()->addError($this->__('This brand no longer exist.'));
             return $this->_redirect('*/*/index');
         }
     }
     //Check $_POST data if the form was submitted
     if ($postData = $this->getRequest()->getPost()) {
         if (isset($_FILES['brand_image']['name']) && $_FILES['brand_image']['name'] != '') {
             try {
                 $uploader = new Varien_File_Uploader('brand_image');
                 $uploader->setAllowedExtensions('jpg', 'jpeg', 'gif', 'png');
                 $uploader->setAllowRenameFiles(false);
                 $uploader->setFilesDispersion(false);
                 $path = Mage::getBaseDir('media') . DS . 'brand/';
                 $uploader->save($path, $_FILES['brand_image']['name']);
                 $name = $uploader->getCorrectFileName($_FILES['brand_image']['name']);
                 $postData['brand_image'] = $name;
             } catch (Exception $e) {
                 Mage::logException($e);
                 $this->_getSession()->addError($e->getMessage());
             }
         }
         try {
             $brand->addData($postData);
             $brand->save();
             $this->_getSession()->addSuccess($this->__('The brand has been saved.'));
             return $this->_redirect('*/*/edit', array('id' => $brand->getId()));
         } catch (Exception $e) {
             Mage::logException($e);
             $this->_getSession()->addError($e->getMessage());
         }
     }
     //Make the current brand object available to blocks
     Mage::register('current_brand', $brand);
     //Instantiate the form container
     $brandEditBlock = $this->getLayout()->createBlock('boolfly_brand/adminhtml_brand_edit');
     $this->loadLayout()->_addContent($brandEditBlock)->renderLayout();
 }
开发者ID:patrickphp4,项目名称:MagentoCodeTutorial,代码行数:47,代码来源:BrandController.php

示例5: saveAction

 public function saveAction()
 {
     if (isset($_FILES['filecsv']['name']) and file_exists($_FILES['filecsv']['tmp_name'])) {
         try {
             $uploader = new Varien_File_Uploader('filecsv');
             $uploader->setAllowedExtensions(array('csv'));
             $uploader->setAllowRenameFiles(true);
             $path = Mage::getBaseDir('var') . DS . 'import' . DS;
             $filename = $uploader->getCorrectFileName($_FILES['filecsv']['name']);
             if (file_exists($path . $filename)) {
                 unlink($path . $filename);
             }
             $uploader->save($path, $filename);
             $this->_getHelper()->processfile($path . $filename);
             Mage::getSingleton('core/session')->addSuccess("File was succefully processed.");
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
         }
     } else {
         Mage::getSingleton('adminhtml/session')->addError("File wasn't uploaded");
     }
     $this->_redirect('*/*/');
 }
开发者ID:xiaoguizhidao,项目名称:autotech_design,代码行数:23,代码来源:CallforpriceController.php

示例6: _uploadFile

 /**
  * Decode file from base64 and upload it to donwloadable 'tmp' folder
  *
  * @param array $fileInfo
  * @param string $type
  * @return string
  */
 protected function _uploadFile($fileInfo, $type)
 {
     $tmpPath = '';
     if ($type == 'sample') {
         $tmpPath = Mage_Downloadable_Model_Sample::getBaseTmpPath();
     } elseif ($type == 'link') {
         $tmpPath = Mage_Downloadable_Model_Link::getBaseTmpPath();
     } elseif ($type == 'link_samples') {
         $tmpPath = Mage_Downloadable_Model_Link::getBaseSampleTmpPath();
     }
     $result = array();
     $url = $fileInfo['url'];
     $remoteFileName = $fileInfo['name'];
     $ioAdapter = new Varien_Io_File();
     $ioAdapter->checkAndCreateFolder($tmpPath);
     $ioAdapter->open(array('path' => $tmpPath));
     $fileName = $tmpPath . DS . Varien_File_Uploader::getCorrectFileName($remoteFileName);
     if ($ioAdapter->cp($url, $fileName)) {
         Mage::helper('core/file_storage_database')->saveFile($fileName);
     }
     $result['file'] = $remoteFileName;
     $result['status'] = 'new';
     $result['name'] = $remoteFileName;
     return Mage::helper('core')->jsonEncode(array($result));
 }
开发者ID:ksawh,项目名称:retailops_magento,代码行数:32,代码来源:Downloadable.php

示例7: savePostResult

 public function savePostResult($config = array())
 {
     try {
         $postData = Mage::app()->getRequest()->getPost();
         if (!empty($config['prefix'])) {
             $postData = Mage::app()->getRequest()->getPost($config['prefix']);
         }
         $result = Mage::getModel('webforms/results');
         $new_result = true;
         if (!empty($postData['result_id'])) {
             $new_result = false;
             $result->load($postData['result_id'])->addFieldArray();
         }
         $this->setData('post_data', $postData['field']);
         $errors = $this->validatePostResult();
         if (count($errors)) {
             foreach ($errors as $error) {
                 Mage::getSingleton('core/session')->addError($error);
                 Mage::getSingleton('core/session')->setData('webform_result_tmp_' . $this->getId(), $postData);
             }
             return false;
         }
         Mage::getSingleton('core/session')->setData('webform_result_tmp_' . $this->getId(), false);
         $iplong = ip2long(Mage::helper('webforms')->getRealIp());
         $files = $this->getUploadedFiles();
         foreach ($files as $field_name => $file) {
             $field_id = str_replace('file_', '', $field_name);
             if ($file['name']) {
                 $postData['field'][$field_id] = Varien_File_Uploader::getCorrectFileName($file['name']);
             }
             if (!empty($postData['delete_file_' . $field_id])) {
                 if ($result->getData('field_' . $field_id)) {
                     //delete the file
                     @unlink($result->getFileFullPath($field_id, $result->getData('field_' . $field_id)));
                 }
                 $postData['field'][$field_id] = '';
             }
         }
         $approve = 1;
         if ($this->getApprove()) {
             $approve = 0;
         }
         $result->setData('field', $postData['field'])->setWebformId($this->getId())->setStoreId(Mage::app()->getStore()->getId())->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId())->setCustomerIp($iplong)->setApproved($approve)->save();
         $fields = Mage::getModel('webforms/fields')->setStoreId($this->getStoreId())->getCollection()->addFilter('webform_id', $this->getId());
         // upload files from $_FILE array
         foreach ($_FILES as $field_name => $file) {
             $field_id = str_replace('file_', '', $field_name);
             // check that field belongs to the form
             foreach ($fields as $field) {
                 if ($field_id == $field->getId()) {
                     if (isset($file['name']) && file_exists($file['tmp_name'])) {
                         try {
                             $uploader = new Varien_File_Uploader($field_name);
                             $uploader->setAllowRenameFiles(false);
                             $uploader->setFilesDispersion(false);
                             $path = $result->getFilePath($field_id);
                             $uploader->save($path, $file['name']);
                         } catch (Exception $e) {
                         }
                     }
                 }
             }
         }
         // upload Ajax files
         $ajax_files = $this->getAjaxFiles();
         foreach ($ajax_files as $field_name => $file) {
             $field_id = str_replace('file_', '', $field_name);
             if (isset($file['name']) && file_exists($file['tmp_name'])) {
                 $path = $result->getFilePath($field_id);
                 @mkdir($path, 0777, true);
                 rename($file['tmp_name'], $path . Varien_File_Uploader::getCorrectFileName($file['name']));
             }
         }
         Mage::dispatchEvent('webforms_result_submit', array('result' => $result, 'webform' => $this));
         // send e-mail
         if ($new_result) {
             $emailSettings = $this->getEmailSettings();
             $result = Mage::getModel('webforms/results')->load($result->getId());
             // send admin notification
             if ($emailSettings['email_enable']) {
                 $result->sendEmail();
             }
             // send customer notification
             if ($this->getDuplicateEmail()) {
                 $result->sendEmail('customer');
             }
             // email contact
             foreach ($fields as $field) {
                 foreach ($result->getData() as $key => $value) {
                     if ($key == 'field_' . $field->getId() && $value && $field->getType() == 'select/contact') {
                         $result->sendEmail('contact', $field->getContactArray($value));
                     }
                     if ($key == 'field_' . $field->getId() && $value && $field->getType() == 'subscribe') {
                         // subscribe to newsletter
                         $customer_email = $result->getCustomerEmail();
                         foreach ($customer_email as $email) {
                             Mage::getModel('newsletter/subscriber')->subscribe($email);
                         }
                     }
                 }
//.........这里部分代码省略.........
开发者ID:monarcmoso,项目名称:beta2,代码行数:101,代码来源:Webforms.php

示例8: addImage

 /**
  * Add image to media gallery and return new filename
  *
  * @param Mage_Catalog_Model_Product $product
  * @param string                     $file              file path of image in file system
  * @param string|array               $mediaAttribute    code of attribute with type 'media_image',
  *                                                      leave blank if image should be only in gallery
  * @param boolean                    $move              if true, it will move source file
  * @param boolean                    $exclude           mark image as disabled in product page view
  * @return string
  */
 public function addImage(Mage_Catalog_Model_Product $product, $file, $mediaAttribute = null, $move = false, $exclude = true)
 {
     $file = realpath($file);
     if (!$file || !file_exists($file)) {
         Mage::throwException(Mage::helper('catalog')->__('Image does not exist.'));
     }
     $pathinfo = pathinfo($file);
     if (!isset($pathinfo['extension']) || !in_array(strtolower($pathinfo['extension']), array('jpg', 'jpeg', 'gif', 'png'))) {
         Mage::throwException(Mage::helper('catalog')->__('Invalid image file type.'));
     }
     $fileName = Varien_File_Uploader::getCorrectFileName($pathinfo['basename']);
     $dispretionPath = Varien_File_Uploader::getDispretionPath($fileName);
     $fileName = $dispretionPath . DS . $fileName;
     $fileName = $this->_getNotDuplicatedFilename($fileName, $dispretionPath);
     $ioAdapter = new Varien_Io_File();
     $ioAdapter->setAllowCreateFolders(true);
     $distanationDirectory = dirname($this->_getConfig()->getTmpMediaPath($fileName));
     try {
         $ioAdapter->open(array('path' => $distanationDirectory));
         if ($move) {
             $ioAdapter->mv($file, $this->_getConfig()->getTmpMediaPath($fileName));
         } else {
             $ioAdapter->cp($file, $this->_getConfig()->getTmpMediaPath($fileName));
             $ioAdapter->chmod($this->_getConfig()->getTmpMediaPath($fileName), 0777);
         }
     } catch (Exception $e) {
         Mage::throwException(Mage::helper('catalog')->__('Failed to move file: %s', $e->getMessage()));
     }
     $fileName = str_replace(DS, '/', $fileName);
     $attrCode = $this->getAttribute()->getAttributeCode();
     $mediaGalleryData = $product->getData($attrCode);
     $position = 0;
     if (!is_array($mediaGalleryData)) {
         $mediaGalleryData = array('images' => array());
     }
     foreach ($mediaGalleryData['images'] as &$image) {
         if (isset($image['position']) && $image['position'] > $position) {
             $position = $image['position'];
         }
     }
     $position++;
     $mediaGalleryData['images'][] = array('file' => $fileName, 'position' => $position, 'label' => '', 'disabled' => (int) $exclude);
     $product->setData($attrCode, $mediaGalleryData);
     if (!is_null($mediaAttribute)) {
         $this->setMediaAttribute($product, $mediaAttribute, $fileName);
     }
     return $fileName;
 }
开发者ID:jpbender,项目名称:mage_virtual,代码行数:59,代码来源:Media.php

示例9: validateUserValue

 /**
  * Validate user input for option
  *
  * @throws Mage_Core_Exception
  * @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...)
  * @return Mage_Catalog_Model_Product_Option_Type_Default
  */
 public function validateUserValue($values)
 {
     AO::getSingleton('checkout/session')->setUseNotice(false);
     $this->setIsValid(true);
     $option = $this->getOption();
     // Set option value from request (Admin/Front reorders)
     if (isset($values[$option->getId()]) && is_array($values[$option->getId()])) {
         if (isset($values[$option->getId()]['order_path'])) {
             $orderFileFullPath = AO::getBaseDir() . $values[$option->getId()]['order_path'];
         } else {
             $this->setUserValue(null);
             return $this;
         }
         $ok = is_file($orderFileFullPath) && is_readable($orderFileFullPath) && isset($values[$option->getId()]['secret_key']) && substr(md5(file_get_contents($orderFileFullPath)), 0, 20) == $values[$option->getId()]['secret_key'];
         $this->setUserValue($ok ? $values[$option->getId()] : null);
         return $this;
     } elseif ($this->getProduct()->getSkipCheckRequiredOption()) {
         $this->setUserValue(null);
         return $this;
     }
     /**
      * Upload init
      */
     $upload = new Zend_File_Transfer_Adapter_Http();
     $file = 'options_' . $option->getId() . '_file';
     try {
         $runValidation = $option->getIsRequire() || $upload->isUploaded($file);
         if (!$runValidation) {
             $this->setUserValue(null);
             return $this;
         }
         $fileInfo = $upload->getFileInfo($file);
         $fileInfo = $fileInfo[$file];
     } catch (Exception $e) {
         $this->setIsValid(false);
         AO::throwException(AO::helper('catalog')->__("Files upload failed"));
     }
     /**
      * Option Validations
      */
     // Image dimensions
     $_dimentions = array();
     if ($option->getImageSizeX() > 0) {
         $_dimentions['maxwidth'] = $option->getImageSizeX();
     }
     if ($option->getImageSizeY() > 0) {
         $_dimentions['maxheight'] = $option->getImageSizeY();
     }
     if (count($_dimentions) > 0) {
         $upload->addValidator('ImageSize', false, $_dimentions);
     }
     // File extension
     $_allowed = $this->_parseExtensionsString($option->getFileExtension());
     if ($_allowed !== null) {
         $upload->addValidator('Extension', false, $_allowed);
     } else {
         $_forbidden = $this->_parseExtensionsString($this->getConfigData('forbidden_extensions'));
         if ($_forbidden !== null) {
             $upload->addValidator('ExcludeExtension', false, $_forbidden);
         }
     }
     /**
      * Upload process
      */
     $this->_initFilesystem();
     if ($upload->isUploaded($file) && $upload->isValid($file)) {
         $extension = pathinfo(strtolower($fileInfo['name']), PATHINFO_EXTENSION);
         $fileName = Varien_File_Uploader::getCorrectFileName($fileInfo['name']);
         $dispersion = Varien_File_Uploader::getDispretionPath($fileName);
         $filePath = $dispersion;
         $destination = $this->getQuoteTargetDir() . $filePath;
         $this->_createWriteableDir($destination);
         $upload->setDestination($destination);
         $fileHash = md5(file_get_contents($fileInfo['tmp_name']));
         $filePath .= DS . $fileHash . '.' . $extension;
         $fileFullPath = $this->getQuoteTargetDir() . $filePath;
         $upload->addFilter('Rename', array('target' => $fileFullPath, 'overwrite' => true));
         if (!$upload->receive()) {
             $this->setIsValid(false);
             AO::throwException(AO::helper('catalog')->__("File upload failed"));
         }
         $_imageSize = @getimagesize($fileFullPath);
         if (is_array($_imageSize) && count($_imageSize) > 0) {
             $_width = $_imageSize[0];
             $_height = $_imageSize[1];
         } else {
             $_width = 0;
             $_height = 0;
         }
         $this->setUserValue(array('type' => $fileInfo['type'], 'title' => $fileInfo['name'], 'quote_path' => $this->getQuoteTargetDir(true) . $filePath, 'order_path' => $this->getOrderTargetDir(true) . $filePath, 'fullpath' => $fileFullPath, 'size' => $fileInfo['size'], 'width' => $_width, 'height' => $_height, 'secret_key' => substr($fileHash, 0, 20)));
     } elseif ($upload->getErrors()) {
         $errors = array();
         foreach ($upload->getErrors() as $errorCode) {
//.........这里部分代码省略.........
开发者ID:ronseigel,项目名称:agent-ohm,代码行数:101,代码来源:Product_Option_Type_File.php

示例10: saveAction

 public function saveAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         //Zend_Debug::dump($data);die();
         //var_dump($this->getRequest()->getParam('status'));exit;
         $data = $this->getRequest()->getPost();
         $program_id = $this->getRequest()->getParam('id');
         $model = Mage::getModel('rewardpoints/cartrules');
         try {
             if (isset($_FILES['promotion_image']['name']) && $_FILES['promotion_image']['name'] != '') {
                 try {
                     /* Starting upload */
                     $uploader = new Varien_File_Uploader('promotion_image');
                     // Any extention would work
                     $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png', 'bmp'));
                     $uploader->setAllowRenameFiles(true);
                     // Set the file upload mode
                     // false -> get the file directly in the specified folder
                     // true -> get the file in the product like folders
                     //	(file.jpg will go in something like /media/f/i/file.jpg)
                     $uploader->setFilesDispersion(false);
                     $file_name = $uploader->getCorrectFileName($_FILES['promotion_image']['name']);
                     // We set media as the upload dir
                     $path = Mage::getBaseDir('media') . DS . "mw_rewardpoint";
                     $uploader->save($path, $file_name);
                 } catch (Exception $e) {
                 }
                 //this way the name is saved in DB
                 //$data['image_name'] = 'mw_affiliate/'.$_FILES['image_name']['name'];
                 $data['promotion_image'] = 'mw_rewardpoint/' . $file_name;
             } else {
                 if (isset($data['promotion_image']['delete']) && $data['promotion_image']['delete'] == 1) {
                     $data['promotion_image'] = '';
                 } else {
                     unset($data['promotion_image']);
                 }
             }
             $customer_group_ids = "";
             $store_view = "";
             if (isset($data["customer_group_ids"])) {
                 $customer_group_ids = implode(",", $data["customer_group_ids"]);
             }
             $data["customer_group_ids"] = $customer_group_ids;
             if (isset($data["store_view"])) {
                 if (in_array("0", $data["store_view"])) {
                     $store_view = '0';
                 } else {
                     $store_view = implode(",", $data["store_view"]);
                 }
             }
             $data["store_view"] = $store_view;
             if (!$data["reward_step"]) {
                 $data["reward_step"] = 0;
             }
             if ($data['rule_position'] == '') {
                 $data['rule_position'] = 0;
             }
             if ($program_id != '') {
                 if (Mage::app()->isSingleStoreMode()) {
                     $data['store_view'] = '0';
                 }
                 $model->setData($data)->setId($program_id);
                 $model->save();
                 // save conditions
                 if (isset($data['rule']['conditions'])) {
                     $data['conditions'] = $data['rule']['conditions'];
                 }
                 if (isset($data['rule']['actions'])) {
                     $data['actions'] = $data['rule']['actions'];
                 }
                 $model->load($program_id);
                 unset($data['rule']);
                 $model->loadPost($data);
                 $model->save();
             }
             if ($program_id == '') {
                 if (Mage::app()->isSingleStoreMode()) {
                     $data['store_view'] = '0';
                 }
                 //Zend_Debug::dump($data);die();
                 $model->setData($data)->save();
                 // save conditions
                 if (isset($data['rule']['conditions'])) {
                     $data['conditions'] = $data['rule']['conditions'];
                 }
                 if (isset($data['rule']['actions'])) {
                     $data['actions'] = $data['rule']['actions'];
                 }
                 unset($data['rule']);
                 $model->loadPost($data);
                 $model->save();
             }
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('rewardpoints')->__('The rule has successfully saved'));
             Mage::getSingleton('adminhtml/session')->setFormData(false);
             if ($this->getRequest()->getParam('back')) {
                 $this->_redirect('*/*/edit', array('id' => $model->getId()));
                 return;
             }
             $this->_redirect('*/*/');
             return;
//.........这里部分代码省略.........
开发者ID:shebin512,项目名称:Magento_Zoff,代码行数:101,代码来源:CartrulesController.php

示例11: _beforeSave

 protected function _beforeSave()
 {
     if (isset($_FILES['layout_file']) && $_FILES['layout_file']['name'] != '') {
         try {
             $uploader = new Varien_File_Uploader('layout_file');
             $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
             $uploader->setAllowRenameFiles(true);
             $uploader->setFilesDispersion(true);
             $this->setLayoutFileName($uploader->getCorrectFileName($_FILES['layout_file']['name']));
             $ext = pathinfo($_FILES['layout_file']['name'], PATHINFO_EXTENSION);
             $result = $uploader->save(Mage::getBaseDir('media') . DS . $this->getUploadPath(), uniqid() . "." . $ext);
             $this->setLayoutFile($this->getUploadPath() . $result['file']);
         } catch (Exception $e) {
             Mage::throwException($this->__('Invalid image format'));
         }
     } else {
         $layoutFile = $this->getLayoutFile();
         if (isset($layoutFile['delete']) && $layoutFile['delete'] == 1) {
             $this->setLayoutFile(NULL);
         } else {
             $this->setLayoutFile($this->layout_file["value"]);
         }
     }
     return parent::_beforeSave();
 }
开发者ID:CE-Webmaster,项目名称:CE-Hub,代码行数:25,代码来源:Page.php

示例12: getDownloadLink

 public function getDownloadLink($field_id, $filename)
 {
     $filename = Varien_File_Uploader::getCorrectFileName($filename);
     $path = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'webforms/' . $this->getId() . '/' . $field_id . '/';
     if ($this->getData('key_' . $field_id)) {
         $path .= $this->getData('key_' . $field_id) . '/';
     }
     $path .= rawurlencode($filename);
     return $path;
 }
开发者ID:smitmanglam,项目名称:staging,代码行数:10,代码来源:Results.php

示例13: processImage

 /**
  *
  * Save the avatar image after checks
  */
 public function processImage()
 {
     $session = $this->_getSession();
     $upload = new Zend_File_Transfer_Adapter_Http();
     $file = 'photo';
     try {
         $runValidation = $upload->isUploaded($file);
         if (!$runValidation) {
             return array();
         }
         $fileInfo = $upload->getFileInfo($file);
         $fileInfo = $fileInfo[$file];
     } catch (Exception $e) {
         // when file exceeds the upload_max_filesize, $_FILES is empty
         if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] > $this->_getUploadMaxFilesize()) {
             $errors[] = Mage::helper('avatar')->__("The file you uploaded is larger than %s Megabytes allowed by server", $this->_bytesToMbytes($this->_getUploadMaxFilesize()));
             return $errors;
             /*Mage::throwException(
               Mage::helper('catalog')->__("The file you uploaded is larger than %s Megabytes allowed by server",
               $this->_bytesToMbytes($this->_getUploadMaxFilesize())
               )
               );*/
         } else {
             Mage::throwException(Mage::helper('avatar')->__("error uploading image"));
         }
     }
     /**
      * Option Validations
      */
     // Image dimensions
     $_dimentions = array();
     $_dimentions['maxwidth'] = '2000';
     $_dimentions['maxheight'] = '2000';
     if (count($_dimentions) > 0) {
         $upload->addValidator('ImageSize', false, $_dimentions);
     }
     // File extension
     $_allowed = $this->_parseExtensionsString("jpg/gif/png");
     if ($_allowed !== null) {
         $upload->addValidator('Extension', false, $_allowed);
     } else {
         $_forbidden = $this->_parseExtensionsString($this->getConfigData('forbidden_extensions'));
         if ($_forbidden !== null) {
             $upload->addValidator('ExcludeExtension', false, $_forbidden);
         }
     }
     // Maximum filesize
     $upload->addValidator('FilesSize', false, array('max' => $this->_getUploadMaxFilesize()));
     /**
      * Upload process
      */
     $this->_initFilesystem();
     if ($upload->isUploaded($file) && $upload->isValid($file)) {
         $extension = pathinfo(strtolower($fileInfo['name']), PATHINFO_EXTENSION);
         $fileName = Varien_File_Uploader::getCorrectFileName($fileInfo['name']);
         $dispersion = Varien_File_Uploader::getDispretionPath($fileName);
         $filePath = $dispersion;
         $destination = $this->getPhotoTargetDir() . $filePath;
         $this->_createWriteableDir($destination);
         $upload->setDestination($destination);
         $fileHash = md5(file_get_contents($fileInfo['tmp_name']));
         $filePath .= DS . $fileHash . '-' . time() . "." . $extension;
         $fileFullPath = $this->getPhotoTargetDir() . $filePath;
         $upload->addFilter('Rename', array('target' => $fileFullPath, 'overwrite' => true));
         if (!$upload->receive($file)) {
             Mage::throwException(Mage::helper('avatar')->__("File upload failed"));
         }
         $_imageSize = @getimagesize($fileFullPath);
         if (is_array($_imageSize) && count($_imageSize) > 0) {
             $_width = $_imageSize[0];
             $_height = $_imageSize[1];
         } else {
             $_width = 0;
             $_height = 0;
         }
         $imageObj = new Varien_Image($fileFullPath);
         $imageObj->constrainOnly(TRUE);
         $imageObj->keepAspectRatio(TRUE);
         $imageObj->keepTransparency(TRUE);
         $imageObj->resize(50);
         $imageObj->save($fileFullPath);
         return $filePath;
     } elseif ($upload->getErrors()) {
         $errors = array();
         foreach ($upload->getErrors() as $errorCode) {
             if ($errorCode == Zend_Validate_File_ExcludeExtension::FALSE_EXTENSION) {
                 $errors[] = Mage::helper('avatar')->__("The file '%s' has an invalid extension", $fileInfo['name']);
             } elseif ($errorCode == Zend_Validate_File_Extension::FALSE_EXTENSION) {
                 $errors[] = Mage::helper('avatar')->__("The file '%s' has an invalid extension", $fileInfo['name']);
             } elseif ($errorCode == Zend_Validate_File_ImageSize::WIDTH_TOO_BIG) {
                 $errors[] = Mage::helper('avatar')->__("Maximum allowed image width for '%s' is %s px.", $fileInfo['name'], $_dimentions['maxwidth']);
             } elseif ($errorCode == Zend_Validate_File_ImageSize::HEIGHT_TOO_BIG) {
                 $errors[] = Mage::helper('avatar')->__("Maximum allowed image height for '%s' is %s px.", $fileInfo['name'], $_dimentions['maxheight']);
             } elseif ($errorCode == Zend_Validate_File_FilesSize::TOO_BIG) {
                 $errors[] = Mage::helper('avatar')->__("The file you uploaded is larger than %s Megabytes allowed by server", $fileInfo['name'], $this->_bytesToMbytes($this->_getUploadMaxFilesize()));
             }
//.........这里部分代码省略.........
开发者ID:astovpak,项目名称:martana,代码行数:101,代码来源:Data.php

示例14: _getFileName

 protected function _getFileName($url, $mediakey)
 {
     $fileName = Varien_File_Uploader::getCorrectFileName(basename($url));
     $fileName = str_replace($mediakey, '', $fileName);
     $fileName = trim($fileName, '_');
     return $fileName;
 }
开发者ID:ksawh,项目名称:retailops_magento,代码行数:7,代码来源:Media.php

示例15: saveAction

 /**
  *
  */
 public function saveAction()
 {
     if ($this->getRequest()->getPost()) {
         try {
             $post_data = $this->getRequest()->getPost();
             $slider_id = $this->getRequest()->getParam('id');
             $slide_model = Mage::getModel('slider/slider');
             $destFolder = rtrim(BP, '/\\') . '/media/ismslider/';
             $timeMarker = time();
             foreach ($post_data['slides'] as $slideId => $values) {
                 if (!empty($values['deleteimage'])) {
                     @unlink($destFolder . $values['deleteimage']);
                     @unlink($destFolder . 'thumb-' . $values['deleteimage']);
                     $post_data['slides'][$slideId]['image'] = '';
                 }
             }
             foreach ($_FILES['slides']['name'] as $slideId => $values) {
                 if (empty($values['image'])) {
                     continue;
                 }
                 if (!is_writable($destFolder)) {
                     Mage::getSingleton('adminhtml/session')->addError('Destination folder is not writable or does not exists.');
                     continue;
                 }
                 $fileName = Varien_File_Uploader::getCorrectFileName($values['image']);
                 $destFile = $destFolder . $timeMarker . '_' . $fileName;
                 $result = move_uploaded_file($_FILES['slides']['tmp_name'][$slideId]['image'], $destFile);
                 if ($result) {
                     chmod($destFile, 0644);
                     $imageProcessor = new Varien_Image($destFile);
                     $imageProcessor->keepAspectRatio(true);
                     $imageProcessor->keepFrame(true);
                     $imageProcessor->keepTransparency(true);
                     $imageProcessor->constrainOnly(false);
                     $imageProcessor->backgroundColor(array(255, 255, 255));
                     $imageProcessor->quality(90);
                     $imageProcessor->resize(172, 60);
                     $imageProcessor->save($destFolder, 'thumb-' . $timeMarker . '_' . $fileName);
                     $post_data['slides'][$slideId]['image'] = $timeMarker . '_' . $fileName;
                     chmod($destFolder, 'thumb-' . $timeMarker . '_' . $fileName, 0644);
                 } else {
                     $post_data['slides'][$slideId]['image'] = '';
                     Mage::getSingleton('adminhtml/session')->addError('File ' . $fileName . ' was not uploaded.');
                 }
             }
             $slide_model->setId($slider_id)->setData($post_data);
             if ($slider_id !== null) {
                 $slide_model->setModifiedTime(new Zend_Db_Expr('NOW()'));
             } else {
                 $slide_model->setCreatedTime(new Zend_Db_Expr('NOW()'));
             }
             $slide_model->save();
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Slider was successfully saved'));
             if ($this->getRequest()->getParam('back')) {
                 $this->_redirect('*/*/edit', array('id' => $slide_model->getId()));
                 return;
             }
             $this->_redirect('*/*/');
             return;
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
             $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
             return;
         }
     }
     $this->_redirect('*/*/');
 }
开发者ID:xiaoguizhidao,项目名称:bilderrahmen,代码行数:70,代码来源:SliderController.php


注:本文中的Varien_File_Uploader::getCorrectFileName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。