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


PHP Varien_File_Uploader::chechAllowedExtension方法代码示例

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


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

示例1: saveAction

 public function saveAction()
 {
     $data = $this->getRequest()->getPost();
     //DebugBreak();
     //If the manufacturer already exits or not
     $collection = Mage::getModel('manufacturer/manufacturer')->getCollection()->addFieldToFilter('menufecturer_name', $data['menufecturer_name']);
     $manufacturer_data = $collection->getData();
     if (count($collection) > 0 && $manufacturer_data[0]['status'] == 1 && $this->getRequest()->getParam('id') != $manufacturer_data[0]['manufacturer_id']) {
         $this->_forward('edit');
         Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Manufacturer Already Exists'));
         //Mage::getSingleton('adminhtml/session')->setFormData(false);
     } else {
         if ($data) {
             if (isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
                 try {
                     /* Starting upload */
                     $uploader = new Varien_File_Uploader('filename');
                     // Any extention would work
                     $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
                     $uploader->setAllowRenameFiles(false);
                     // Set the file upload mode
                     // false -> get the file directly in the specified folder
                     // true -> get the file in the product like folders
                     //	(file.jpg will go in something like /media/f/i/file.jpg)
                     $uploader->setFilesDispersion(false);
                     // We set media/Manufacturer as the upload dir
                     $path = Mage::getBaseDir('media') . DS . "Manufacturer" . DS;
                     $uploader->save($path, str_replace(" ", "_", $_FILES['filename']['name']));
                 } catch (Exception $e) {
                 }
                 //If the uploaded file is not image it will mnot allow to save manufacturer
                 $fileName = $_FILES['filename']['name'];
                 $fileName = explode(".", $fileName);
                 //this way the name is saved in DB
                 try {
                     if ($uploader->chechAllowedExtension($fileName[1])) {
                         $data['filename'] = str_replace(" ", "_", $_FILES['filename']['name']);
                     } else {
                         Mage::getSingleton('adminhtml/session')->addError("Upload Image Files Only");
                         Mage::getSingleton('adminhtml/session')->setFormData($data);
                         $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
                         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;
                 }
             }
             $model = Mage::getModel('manufacturer/manufacturer');
             $model->setData($data)->setId($this->getRequest()->getParam('id'));
             try {
                 if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
                     $model->setCreatedTime(now())->setUpdateTime(now());
                 } else {
                     $model->setUpdateTime(now());
                 }
                 $model->save();
                 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('manufacturer')->__('Manufacturer 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('manufacturer')->__('Unable to find manufacturer to save'));
         $this->_redirect('*/*/');
     }
 }
开发者ID:monarcmoso,项目名称:beta2,代码行数:78,代码来源:ManufacturerController.php


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