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


PHP Varien_File_Uploader::checkMimeType方法代码示例

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


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

示例1: savemarcaAction

 public function savemarcaAction()
 {
     $params = $this->getRequest()->getParams();
     $id = $params['id'];
     $name = $params['name'];
     $sort_order = $params['sort_order'];
     $image = $params['image'];
     $link = $params['link'];
     $attribute_marca_id = Mage::getModel('marcascategoria/marcas')->getAttributeMarcaId();
     $attr_model = Mage::getModel('catalog/resource_eav_attribute');
     $attr_model->load($attribute_marca_id);
     $data = array();
     $path = Mage::getBaseDir('media') . DS . 'wysiwyg';
     try {
         if ($id) {
             // edição
             // exclui imagem caso esteja enviando outra
             $image = Mage::getModel('marcascategoria/marcas')->getImagemmarca($id);
             if ($params['image']['delete'] == 1) {
                 $image = strstr($image, 'wysiwyg/');
                 $mediaurl = Mage::getBaseDir('media') . DS . $image;
                 if (is_file($mediaurl)) {
                     unlink($mediaurl);
                     // apaga imagem antiga
                 }
             }
             //enviando imagem para media/wysiwyg
             if ($_FILES['image']['tmp_name']) {
                 $uploader = new Varien_File_Uploader('image');
                 $allow_mime_type = array("image/jpeg", "image/pjpeg", "image/jpeg", "image/pjpeg", "image/png", "image/gif");
                 if (!$uploader->checkMimeType($allow_mime_type)) {
                     Mage::throwException("Arquivo inválido.");
                 }
                 $uploader->setAllowRenameFiles(false);
                 $uploader->setFilesDispersion(false);
                 $uploader->save($path, $_FILES['image']['name']);
                 $image = 'wysiwyg/' . $_FILES['image']['name'];
             } else {
                 $image = $image;
             }
             $data['option'] = array('value' => array($id => array(0 => $name)), 'order' => array($id => $sort_order), 'thumb' => array($id => $link), 'image' => array($id => $image));
             $attr_model->addData($data);
         } else {
             // inserção
             //enviando imagem para media/wysiwyg
             if (isset($_FILES['image'])) {
                 $uploader = new Varien_File_Uploader('image');
                 $allow_mime_type = array("image/jpeg", "image/pjpeg", "image/jpeg", "image/pjpeg", "image/png", "image/gif");
                 if (!$uploader->checkMimeType($allow_mime_type)) {
                     Mage::throwException("Arquivo inválido.");
                 }
                 $uploader->setAllowRenameFiles(false);
                 $uploader->setFilesDispersion(false);
                 $uploader->save($path, $_FILES['image']['name']);
                 $image = 'wysiwyg/' . $_FILES['image']['name'];
             }
             $value['option'] = array($name);
             $result = array('value' => $value);
             $attr_model->setData('option', $result);
             $option_id = Mage::getModel('marcascategoria/marcas')->getMarcaOptionId($name);
             $data['option'] = array('value' => array($option_id => array(0 => $name)), 'order' => array($option_id => $sort_order), 'thumb' => array($option_id => $link), 'image' => array($option_id => $image));
             $attr_model->addData($data);
         }
         $attr_model->save();
         Mage::getSingleton('adminhtml/session')->addSuccess('Attributo salvo com sucesso.');
         $this->_redirect('*/*/listamarcas');
     } catch (Exception $e) {
         Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
         $this->_redirect('*/*/gerenciarmarcas');
     }
 }
开发者ID:xiaoguizhidao,项目名称:emporiodopara,代码行数:71,代码来源:AdminController.php

示例2: saveAction

 public function saveAction()
 {
     $params = $this->getRequest()->getParams();
     $files = $_FILES;
     $_active = $params['active'];
     $_name = $params['name'];
     $_link = $params['link'];
     $_type = $params['type'];
     $_first_date = $params['first_date'];
     $_final_date = $params['final_date'];
     $_id = 0;
     if (array_key_exists('id', $params)) {
         $_id = $params['id'];
         $banner = Mage::getModel('banner/banner')->load($_id);
         $old_image = $banner->getData('image');
     } else {
         $banner = Mage::getModel('banner/banner');
     }
     if (array_key_exists('category', $params)) {
         $_category = $params['category'];
         $_category = $_category[0];
     } else {
         $_category = '';
     }
     $_order = $params['ordem'];
     $banner->setData('active', $_active);
     $banner->setData('name', $_name);
     $banner->setData('link', $_link);
     $banner->setData('type', $_type);
     if ($_first_date != '') {
         $date = new Zend_Date($_first_date);
         $banner->setData('first_date', $date->get('YYYY-MM-dd'));
     }
     if ($_final_date != '') {
         $date = new Zend_Date($_final_date);
         $banner->setData('final_date', $date->get('YYYY-MM-dd'));
     }
     $banner->setData('category', $_category);
     $banner->setData('ordem', $_order);
     // Gravação de imagem
     $path = Mage::getBaseDir('media') . DS . 'banner';
     if (!is_dir($path)) {
         mkdir($path);
         chmod($path, 0777);
     }
     if ($_id != 0 && $files['image']['name'] != '' || $_id == 0) {
         if ($_id != 0) {
             Mage::getModel('banner/banner')->deleteImage($old_image);
         }
         if (is_file($path . DS . $files['image']['name'])) {
             $files['image']['name'] = 'ex_' . $files['image']['name'];
         }
         if ($files['image']['name']) {
             $banner->setData('image', 'media' . '/' . 'banner' . '/' . $files['image']['name']);
         } else {
             $banner->setData('image', '');
         }
         try {
             $uploader = new Varien_File_Uploader('image');
             $allow_mime_type = array("image/jpeg", "image/pjpeg", "image/jpeg", "image/pjpeg", "image/png", "application/x-shockwave-flash", "image/gif");
             if (!$uploader->checkMimeType($allow_mime_type)) {
                 Mage::throwException("Arquivo inválido.");
             }
             $uploader->setAllowRenameFiles(false);
             $uploader->setFilesDispersion(false);
             $uploader->save($path, $files['image']['name']);
             $data['datafile'] = $files['image']['name'];
             $banner->save();
             Mage::getSingleton('adminhtml/session')->addSuccess('Operação Realizada com Sucesso !');
             $this->_redirect('*/*/grid');
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
             $this->_redirect("*/*/register");
         }
     } else {
         $banner->save();
         Mage::getSingleton('adminhtml/session')->addSuccess('Operação Realizada com Sucesso !');
         $this->_redirect('*/*/grid');
     }
 }
开发者ID:xiaoguizhidao,项目名称:emporiodopara,代码行数:80,代码来源:AdminController.php


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