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


PHP Varien_File_Uploader::setAllowCreateFolders方法代码示例

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


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

示例1: afterSave

 /**
  * 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;
 }
开发者ID:eniuz,项目名称:entitytype-manager,代码行数:34,代码来源:Image.php

示例2: saveAction

 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('*/*/');
 }
开发者ID:commercekitchen,项目名称:dualeyewear-magento,代码行数:57,代码来源:LocationController.php

示例3: saveAction

 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('*/*/');
 }
开发者ID:vinayshuklasourcefuse,项目名称:sareez,代码行数:55,代码来源:TestimonialController.php

示例4: saveAction

 /**
  * 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('*/*');
 }
开发者ID:pette87,项目名称:Magento-DebitPayment,代码行数:54,代码来源:BankdataController.php

示例5: saveAction

 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('*/*/');
 }
开发者ID:Tronglx,项目名称:magento,代码行数:49,代码来源:HelloController.php

示例6: save

 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('');
     }
 }
开发者ID:vinayshuklasourcefuse,项目名称:sareez,代码行数:49,代码来源:FormController.php

示例7: massImportAction

 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');
         }
     }
 }
开发者ID:vasuscoin,项目名称:shopping_cart_price_rule_import,代码行数:45,代码来源:QuoteController.php

示例8: produploadAction

 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();
 }
开发者ID:mSupply,项目名称:runnable_test_repo,代码行数:45,代码来源:IndexController.php

示例9: _saveAttachment

 /**
  * 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;
 }
开发者ID:beejhuff,项目名称:rootd-link,代码行数:26,代码来源:LinkController.php

示例10: salvarImagem

 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;
 }
开发者ID:xiaoguizhidao,项目名称:emporiodopara,代码行数:41,代码来源:AdminController.php

示例11: _uploadFiles

 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());
     }
 }
开发者ID:Aleksandr-Kachura,项目名称:magento,代码行数:21,代码来源:ItemsController.php

示例12: uploadAction

 /**
  * 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));
     }
 }
开发者ID:techpub,项目名称:PIMGento,代码行数:25,代码来源:TaskController.php

示例13: _uploadAndGetName

 /**
  * 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 '';
 }
开发者ID:sshegde123,项目名称:wmp8,代码行数:34,代码来源:Temples.php

示例14: handleUpload

 /**
  * @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;
 }
开发者ID:adamj88,项目名称:RK_TypeCMS,代码行数:32,代码来源:Observer.php

示例15: manualInstallUploadAction

 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('*');
 }
开发者ID:sagmahajan,项目名称:aswan_release,代码行数:58,代码来源:LicenseController.php


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