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


PHP Mage_Core_Model_File_Uploader::save方法代码示例

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


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

示例1: beforeFieldSave

 public function beforeFieldSave($value, $oldValue)
 {
     $value = parent::beforeFieldSave($value, $oldValue);
     $template = $this->getTemplate();
     /** @var $fileHelper Webguys_Easytemplate_Helper_File */
     $fileHelper = Mage::helper('easytemplate/file');
     $destinationPath = $fileHelper->getDestinationFilePath($template->getGroupId(), $template->getId());
     if ($oldValue && ($value && $oldValue != $value || $this->_deleteFile)) {
         // Delete the old file
         $oldFilePath = sprintf('%s/%s', $destinationPath, $oldValue);
         if (file_exists($oldFilePath)) {
             @unlink($oldFilePath);
         }
     }
     if ($value) {
         $fileHelper->createTmpPath($template->getGroupId(), $template->getId());
         if ($this->uploadComplete()) {
             $uploaderData = array('tmp_name' => $this->extractFilePostInformation('tmp_name'), 'name' => $value);
             $uploader = new Mage_Core_Model_File_Uploader($uploaderData);
             //$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png','pdf'));
             $uploader->addValidateCallback('easytemplate_template_file', $fileHelper, 'validateUploadFile');
             $uploader->setAllowRenameFiles(false);
             $uploader->setFilesDispersion(false);
             $result = $uploader->save($destinationPath);
             Mage::dispatchEvent('easytemplate_upload_file_after', array('result' => $result));
             $value = $result['file'];
         } else {
             // TODO: Error handling
         }
     }
     return $value;
 }
开发者ID:riker09,项目名称:EasyTemplate,代码行数:32,代码来源:File.php

示例2: uploadAction

 public function uploadAction()
 {
     try {
         $pattern = "/([0-9]+\\.[0-9]+\\.[0-9]+)(?:\\.[0-9]+)*/";
         $matches = array();
         preg_match($pattern, Mage::getVersion(), $matches);
         if (version_compare($matches[1], '1.5.1', '<')) {
             $uploader = new Varien_File_Uploader('image');
         } else {
             $uploader = new Mage_Core_Model_File_Uploader('image');
         }
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->addValidateCallback('catalog_product_image', Mage::helper('catalog/image'), 'validateUploadFile');
         $uploader->setAllowRenameFiles(true);
         $uploader->setFilesDispersion(true);
         $result = $uploader->save($this->getMagicslideshowBaseMediaPath());
         /**
          * Workaround for prototype 1.7 methods "isJSON", "evalJSON" on Windows OS
          */
         $result['tmp_name'] = str_replace(DS, "/", $result['tmp_name']);
         $result['path'] = str_replace(DS, "/", $result['path']);
         $result['url'] = $this->getMagicslideshowMediaUrl($result['file']);
         $result['file'] = $result['file'];
         $result['cookie'] = array('name' => session_name(), 'value' => $this->_getSession()->getSessionId(), 'lifetime' => $this->_getSession()->getCookieLifetime(), 'path' => $this->_getSession()->getCookiePath(), 'domain' => $this->_getSession()->getCookieDomain());
     } catch (Exception $e) {
         $result = array('error' => $e->getMessage(), 'errorcode' => $e->getCode());
     }
     $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
 }
开发者ID:CE-Webmaster,项目名称:CE-Hub,代码行数:29,代码来源:GalleryController.php

示例3: saveFlag

 public function saveFlag(Varien_Event_Observer $observer)
 {
     $store = $observer->getEvent()->getStore();
     $data = Mage::app()->getRequest()->getPost();
     if (!empty($_FILES)) {
         if (isset($_FILES['flag']['name']) && $_FILES['flag']['name'] != '') {
             try {
                 $uploader = new Mage_Core_Model_File_Uploader('flag');
                 $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png', 'svg'));
                 $uploader->setAllowRenameFiles(true);
                 $uploader->setFilesDispersion(false);
                 $dirPath = Mage::getBaseDir('media') . DS . 'store_flag';
                 $result = $uploader->save($dirPath, $_FILES['flag']['name']);
             } catch (Exception $e) {
                 Mage::log($e->getMessage());
             }
             $store->setFlag('store_flag' . $result['file']);
         } elseif (isset($data['flag']) && is_array($data['flag'])) {
             if (isset($data['flag']['delete']) && $data['flag']['delete'] === "1") {
                 $store->setFlag(null);
             } else {
                 $store->setFlag($data['flag']['value']);
             }
         }
     }
 }
开发者ID:outeredge,项目名称:edge-magento-module-storeflag,代码行数:26,代码来源:Store.php

示例4: afterSave

 /**
  * After attribute is saved upload file to media
  * folder and save it to its associated product.
  *
  * @param  Mage_Catalog_Model_Product $object
  * @return Jvs_FileAttribute_Model_Attribute_Backend_File
  */
 public function afterSave($object)
 {
     $value = $object->getData($this->getAttribute()->getName());
     if (is_array($value) && !empty($value['delete'])) {
         $object->setData($this->getAttribute()->getName(), '');
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
         return;
     }
     try {
         $uploadedFile = new Varien_Object();
         $uploadedFile->setData('name', $this->getAttribute()->getName());
         $uploadedFile->setData('allowed_extensions', array('jpg', 'jpeg', 'gif', 'png', 'tif', 'tiff', 'mpg', 'mpeg', 'mp3', 'wav', 'pdf', 'txt'));
         Mage::dispatchEvent('jvs_fileattribute_allowed_extensions', array('file' => $uploadedFile));
         $uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
         $uploader->setAllowedExtensions($uploadedFile->getData('allowed_extensions'));
         $uploader->setAllowRenameFiles(true);
         $uploader->setFilesDispersion(true);
         $uploader->save(Mage::getBaseDir('media') . '/catalog/product');
     } catch (Exception $e) {
         return $this;
     }
     $fileName = $uploader->getUploadedFileName();
     if ($fileName) {
         $object->setData($this->getAttribute()->getName(), $fileName);
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
     }
     return $this;
 }
开发者ID:jahvi,项目名称:FileUploadAttribute,代码行数:35,代码来源:File.php

示例5: saveFields

 public function saveFields(Varien_Event_Observer $observer)
 {
     $model = $observer->getEvent()->getPage();
     $request = $observer->getEvent()->getRequest();
     if (isset($_FILES['image']['name']) && $_FILES['image']['name'] != '') {
         try {
             $uploader = new Mage_Core_Model_File_Uploader('image');
             $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
             $uploader->setAllowRenameFiles(true);
             $uploader->setFilesDispersion(false);
             $dirPath = Mage::getBaseDir('media') . DS . 'page' . DS;
             $result = $uploader->save($dirPath, $_FILES['image']['name']);
         } catch (Exception $e) {
             Mage::log($e->getMessage());
         }
         $model->setImage('page/' . $result['file']);
     } else {
         $data = $request->getPost();
         if (isset($data['image']) && isset($data['image']['delete']) && $data['image']['delete'] == 1) {
             $model->setImage(false);
         } elseif (isset($data['image']) && is_array($data['image'])) {
             $model->setImage($data['image']['value']);
         }
     }
     if (empty($model->getPageType())) {
         $model->setPageType(null);
     }
 }
开发者ID:outeredge,项目名称:edge-magento-module-pages,代码行数:28,代码来源:Page.php

示例6: save

 public function save($destinationFolder, $newFileName = null)
 {
     if (!Mage::getStoreConfigFlag('magefm_cdn/general/enabled')) {
         return parent::save($destinationFolder, $newFileName);
     }
     $this->_validateFile();
     $this->_result = false;
     $fileName = isset($newFileName) ? $newFileName : $this->_file['name'];
     $fileName = self::getCorrectFileName($fileName);
     if ($this->_enableFilesDispersion) {
         $fileName = $this->correctFileNameCase($fileName);
         $this->_dispretionPath = self::getDispretionPath($fileName);
     }
     if ($this->_allowRenameFiles) {
         $fileName = self::getNewFileName($destinationFolder . $this->_dispretionPath, $fileName);
     }
     $destinationFile = $destinationFolder . $this->_dispretionPath . '/' . $fileName;
     $this->_result = $this->_moveFile($this->_file['tmp_name'], $destinationFile);
     if ($this->_result && $this->_result['success']) {
         $this->_result = array('tmp_name' => $this->_file['tmp_name'], 'file' => $fileName, 'url' => $this->_result['url'], 'path' => $destinationFolder . $this->_dispretionPath);
         $this->_uploadedFileName = $fileName;
         $this->_uploadedFileDir = $destinationFolder . $this->_dispretionPath;
         $this->_afterSave($this->_result);
     }
     return $this->_result;
 }
开发者ID:carriercomm,项目名称:cdn-17,代码行数:26,代码来源:Uploader.php

示例7: uploadAction

 /**
  * Upload file controller action
  */
 public function uploadAction()
 {
     $type = $this->getRequest()->getParam('type');
     $tmpPath = '';
     if ($type == 'samples') {
         $tmpPath = Mage_Downloadable_Model_Sample::getBaseTmpPath();
     } elseif ($type == 'links') {
         $tmpPath = Mage_Downloadable_Model_Link::getBaseTmpPath();
     } elseif ($type == 'link_samples') {
         $tmpPath = Mage_Downloadable_Model_Link::getBaseSampleTmpPath();
     }
     $result = array();
     try {
         $uploader = new Mage_Core_Model_File_Uploader($type);
         $uploader->setAllowRenameFiles(true);
         $uploader->setFilesDispersion(true);
         $result = $uploader->save($tmpPath);
         if (isset($result['file'])) {
             $fullPath = rtrim($tmpPath, DS) . DS . ltrim($result['file'], DS);
             Mage::helper('Mage_Core_Helper_File_Storage_Database')->saveFile($fullPath);
         }
         $result['cookie'] = array('name' => session_name(), 'value' => $this->_getSession()->getSessionId(), 'lifetime' => $this->_getSession()->getCookieLifetime(), 'path' => $this->_getSession()->getCookiePath(), 'domain' => $this->_getSession()->getCookieDomain());
     } catch (Exception $e) {
         $result = array('error' => $e->getMessage(), 'errorcode' => $e->getCode());
     }
     $this->getResponse()->setBody(Mage::helper('Mage_Core_Helper_Data')->jsonEncode($result));
 }
开发者ID:relue,项目名称:magento2,代码行数:30,代码来源:FileController.php

示例8: afterSave

 /**
  * Save uploaded file and set its name to category
  *
  * @param Varien_Object $object
  */
 public function afterSave($object)
 {
     $value = $object->getData($this->getAttribute()->getName());
     if (is_array($value) && !empty($value['delete'])) {
         $object->setData($this->getAttribute()->getName(), '');
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
         return;
     }
     $path = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category' . DS;
     try {
         $uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->setAllowRenameFiles(true);
         $uploader->addValidateCallback(Mage_Core_Model_File_Validator_Image::NAME, new Mage_Core_Model_File_Validator_Image(), "validate");
         $result = $uploader->save($path);
         $object->setData($this->getAttribute()->getName(), $result['file']);
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
     } catch (Exception $e) {
         if ($e->getCode() != Mage_Core_Model_File_Uploader::TMP_NAME_EMPTY) {
             Mage::logException($e);
         }
         /** @TODO ??? */
         return;
     }
 }
开发者ID:lynxtdc,项目名称:aromaworks,代码行数:30,代码来源:Image.php

示例9: uploadAction

 /**
  * Upload file controller action
  */
 public function uploadAction()
 {
     $type = $this->getRequest()->getParam('type');
     $tmpPath = '';
     if ($type == 'samples') {
         $tmpPath = Mage_Downloadable_Model_Sample::getBaseTmpPath();
     } elseif ($type == 'links') {
         $tmpPath = Mage_Downloadable_Model_Link::getBaseTmpPath();
     } elseif ($type == 'link_samples') {
         $tmpPath = Mage_Downloadable_Model_Link::getBaseSampleTmpPath();
     }
     $result = array();
     try {
         $uploader = new Mage_Core_Model_File_Uploader($type);
         $uploader->setAllowRenameFiles(true);
         $uploader->setFilesDispersion(true);
         $result = $uploader->save($tmpPath);
         /**
          * Workaround for prototype 1.7 methods "isJSON", "evalJSON" on Windows OS
          */
         $result['tmp_name'] = str_replace(DS, "/", $result['tmp_name']);
         $result['path'] = str_replace(DS, "/", $result['path']);
         if (isset($result['file'])) {
             $fullPath = rtrim($tmpPath, DS) . DS . ltrim($result['file'], DS);
             Mage::helper('core/file_storage_database')->saveFile($fullPath);
         }
         $result['cookie'] = array('name' => session_name(), 'value' => $this->_getSession()->getSessionId(), 'lifetime' => $this->_getSession()->getCookieLifetime(), 'path' => $this->_getSession()->getCookiePath(), 'domain' => $this->_getSession()->getCookieDomain());
     } catch (Exception $e) {
         $result = array('error' => $e->getMessage(), 'errorcode' => $e->getCode());
     }
     $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
 }
开发者ID:cewolf2002,项目名称:magento,代码行数:35,代码来源:FileController.php

示例10: afterSave

 /**
  * After save
  *
  * @param Varien_Object $object
  * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Image
  */
 public function afterSave($object)
 {
     $value = $object->getData($this->getAttribute()->getName());
     if (is_array($value) && !empty($value['delete'])) {
         $object->setData($this->getAttribute()->getName(), '');
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
         return;
     }
     try {
         $uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->setAllowRenameFiles(true);
         $uploader->setFilesDispersion(true);
         $uploader->addValidateCallback(Mage_Core_Model_File_Validator_Image::NAME, new Mage_Core_Model_File_Validator_Image(), "validate");
         $uploader->save(Mage::getBaseDir('media') . '/catalog/product');
         $fileName = $uploader->getUploadedFileName();
         if ($fileName) {
             $object->setData($this->getAttribute()->getName(), $fileName);
             $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
         }
     } catch (Exception $e) {
         return $this;
     }
     return $this;
 }
开发者ID:nja78,项目名称:Magento-Pre-Patched-Files,代码行数:31,代码来源:Image.php

示例11: uploadAction

    public function uploadAction()
    {
        try {
            $uploader = new Mage_Core_Model_File_Uploader('file');
            $uploader->setAllowedExtensions();
            $uploader->setAllowRenameFiles(true);
            $uploader->setFilesDispersion(true);
            $result = $uploader->save(
                            Mage::getSingleton('catalog/product_media_config')->getBaseTmpMediaPath()
            );

            $result['url'] = Mage::getSingleton('catalog/product_media_config')->getTmpMediaUrl($result['file']);
            $result['cookie'] = array(
                'name' => session_name(),
                'value' => $this->_getSession()->getSessionId(),
                'lifetime' => $this->_getSession()->getCookieLifetime(),
                'path' => $this->_getSession()->getCookiePath(),
                'domain' => $this->_getSession()->getCookieDomain()
            );
        } catch (Exception $e) {
            $result = array(
                'error' => $e->getMessage(),
                'errorcode' => $e->getCode());
        }

        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }
开发者ID:netz98,项目名称:N98_InfoFiles,代码行数:27,代码来源:FilesController.php

示例12: _beforeSave

 /**
  * Save uploaded file before saving config value
  *
  * @return Mage_Adminhtml_Model_System_Config_Backend_File
  */
 protected function _beforeSave()
 {
     $value = $this->getValue();
     if (is_array($value) && !empty($value['delete'])) {
         $this->setValue('');
     }
     if ($_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value']) {
         $uploadDir = $this->_getUploadDir();
         try {
             $file = array();
             $tmpName = $_FILES['groups']['tmp_name'];
             $file['tmp_name'] = $tmpName[$this->getGroupId()]['fields'][$this->getField()]['value'];
             $name = $_FILES['groups']['name'];
             $file['name'] = $name[$this->getGroupId()]['fields'][$this->getField()]['value'];
             $uploader = new Mage_Core_Model_File_Uploader($file);
             $uploader->setAllowedExtensions($this->_getAllowedExtensions());
             $uploader->setAllowRenameFiles(true);
             $result = $uploader->save($uploadDir);
         } catch (Exception $e) {
             Mage::throwException($e->getMessage());
             return $this;
         }
         $filename = $result['file'];
         if ($filename) {
             if ($this->_addWhetherScopeInfo()) {
                 $filename = $this->_prependScopeInfo($filename);
             }
             $this->setValue($filename);
         }
     }
     return $this;
 }
开发者ID:natxetee,项目名称:magento2,代码行数:37,代码来源:File.php

示例13: importAction

 public function importAction()
 {
     try {
         $productId = $this->getRequest()->getParam('id');
         $fileName = $this->getRequest()->getParam('Filename');
         $path = Mage::getBaseDir('var') . DS . 'import' . DS;
         $uploader = new Mage_Core_Model_File_Uploader('file');
         $uploader->setAllowedExtensions(array('csv'));
         $uploader->setAllowRenameFiles(false);
         $uploader->setFilesDispersion(false);
         $result = $uploader->save($path, $fileName);
         $io = new Varien_Io_File();
         $io->open(array('path' => $path));
         $io->streamOpen($path . $fileName, 'r');
         $io->streamLock(true);
         while ($data = $io->streamReadCsv(';', '"')) {
             if ($data[0]) {
                 $model = Mage::getModel('giftcards/pregenerated')->load($data[0], 'card_code');
                 if ($model->getId()) {
                     continue;
                 }
                 $model->setCardCode($data[0]);
                 $model->setCardStatus(1);
                 $model->setProductId($productId);
                 $model->save();
             } else {
                 continue;
             }
         }
     } catch (Exception $e) {
         $result = array('error' => $e->getMessage(), 'errorcode' => $e->getCode());
     }
     $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
 }
开发者ID:enjoy2000,项目名称:gemz,代码行数:34,代码来源:ProductController.php

示例14: afterSave

 /**
  * Save uploaded file and set its name to category
  *
  * @param Varien_Object $object
  * @return Mage_Catalog_Model_Category_Attribute_Backend_Image
  */
 public function afterSave($object)
 {
     $value = $object->getData($this->getAttribute()->getName());
     // if no image was set - nothing to do
     if (empty($value) && empty($_FILES)) {
         return $this;
     }
     if (is_array($value) && !empty($value['delete'])) {
         $object->setData($this->getAttribute()->getName(), '');
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
         return $this;
     }
     $path = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category' . DS;
     try {
         $uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
         $uploader->setAllowRenameFiles(true);
         $result = $uploader->save($path);
         $object->setData($this->getAttribute()->getName(), $result['file']);
         $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
     } catch (Exception $e) {
         if ($e->getCode() != Mage_Core_Model_File_Uploader::TMP_NAME_EMPTY) {
             Mage::logException($e);
         }
         /** @TODO ??? */
     }
     return $this;
 }
开发者ID:natxetee,项目名称:magento2,代码行数:34,代码来源:Image.php

示例15: saveCustomOptionImages

 public function saveCustomOptionImages(Varien_Event_Observer $observer)
 {
     if (!isset($_FILES) || empty($_FILES) || !isset($_FILES['product'])) {
         return;
     }
     $product = $observer->getEvent()->getProduct();
     $productData = $observer->getEvent()->getRequest()->getPost('product');
     if (isset($productData['options']) && !$product->getOptionsReadonly()) {
         if (isset($_FILES['product']['name']['options'])) {
             $images = array();
             foreach ($_FILES['product'] as $attr => $options) {
                 if (isset($options['options'])) {
                     foreach ($options['options'] as $optionId => $values) {
                         if (isset($values['values'])) {
                             foreach ($values['values'] as $valueId => $data) {
                                 $key = 'option_' . $optionId . '_value_' . $valueId;
                                 if (!isset($images[$key])) {
                                     $images[$key] = array();
                                 }
                                 $images[$key][$attr] = $data['image'];
                             }
                         }
                     }
                 }
             }
             foreach ($images as $imageName => $imageData) {
                 $_FILES[$imageName] = $imageData;
             }
         }
         foreach ($productData['options'] as $optionId => $option) {
             if (!empty($option['values'])) {
                 foreach ($option['values'] as $valueId => $value) {
                     $imageName = 'option_' . $optionId . '_value_' . $valueId;
                     if (!isset($_FILES[$imageName]) || empty($_FILES[$imageName]) || $_FILES[$imageName]['name'] === "") {
                         continue;
                     }
                     try {
                         $uploader = new Mage_Core_Model_File_Uploader($imageName);
                         $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                         $uploader->setAllowRenameFiles(true);
                         $uploader->setFilesDispersion(false);
                         $dirPath = Mage::getBaseDir('media') . DS . 'custom_option_image' . DS;
                         $result = $uploader->save($dirPath, $_FILES[$imageName]['name']);
                     } catch (Exception $e) {
                         Mage::log($e->getMessage());
                     }
                     $productData['options'][$optionId]['values'][$valueId]['image'] = 'custom_option_image/' . $result['file'];
                     $product->setCanSaveCustomOptions(true);
                 }
             }
         }
         $product->setProductOptions($productData['options']);
     }
 }
开发者ID:outeredge,项目名称:edge-magento-module-customoptionimage,代码行数:54,代码来源:Product.php


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