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


PHP Zend_File_Transfer_Adapter_Http::hasFilter方法代码示例

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


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

示例1: _uploadImages

 /**
  * Handler for pictures/video upload interface
  * @return array
  */
 private function _uploadImages($savePath = null, $resize = true)
 {
     $miscConfig = Zend_Registry::get('misc');
     if (!$savePath) {
         //useful if file submited directly to this method
         $savePath = $this->_getSavePath();
     }
     $this->_uploadHandler->clearValidators()->addValidator('Extension', false, array('jpeg', 'jpg', 'png', 'gif'))->addValidator('ImageSize', false, array('maxwidth' => $miscConfig['imgMaxWidth'], 'maxheight' => $miscConfig['imgMaxWidth']));
     if ($this->_checkMime) {
         $this->_uploadHandler->addValidator(new Validators_MimeType(array('image/gif', 'image/jpeg', 'image/jpg', 'image/png')), false);
     }
     $receivePath = $resize ? $savePath . DIRECTORY_SEPARATOR . 'original' : $savePath;
     if ($this->_uploadHandler->isUploaded() && $this->_uploadHandler->isValid()) {
         if (!is_dir($receivePath)) {
             try {
                 Tools_Filesystem_Tools::mkDir($receivePath);
             } catch (Exceptions_SeotoasterException $e) {
                 error_log($e->getMessage());
             }
         }
         if (!$this->_uploadHandler->hasFilter('Rename')) {
             /**
              * Renaming file if additional field 'name' was submited with file
              */
             $filterChain = new Zend_Filter();
             $filterChain->addFilter(new Zend_Filter_StringTrim())->addFilter(new Zend_Filter_StringToLower('UTF-8'))->addFilter(new Zend_Filter_PregReplace(array('match' => '/[^\\w\\d_]+/u', 'replace' => '-')));
             // filtering the img name
             $expFileName = explode('.', $this->getRequest()->getParam('name', false));
             $fileExt = array_pop($expFileName);
             $name = implode($expFileName);
             $newName = $filterChain->filter($name) . '.' . $fileExt;
             if (false !== $newName) {
                 $this->_uploadHandler->addFilter('Rename', array('target' => $receivePath . DIRECTORY_SEPARATOR . $newName, 'overwrite' => true));
             } else {
                 $this->_uploadHandler->addFilter('Rename', array('target' => $receivePath, 'overwite' => true));
             }
         }
         if ($this->_uploadHandler->receive()) {
             $fileInfo = current($this->_uploadHandler->getFileInfo());
         } else {
             return array('error' => true, 'result' => $this->_uploadHandler->getMessages());
         }
         if ($resize) {
             $status = Tools_Image_Tools::batchResize($fileInfo['tmp_name'], $savePath);
         } else {
             $status = true;
         }
         if (isset($this->_helper->session->imageQualityPreview)) {
             unset($this->_helper->session->imageQualityPreview);
             Tools_Image_Tools::optimizeImage($fileInfo['tmp_name'], self::PREVIEW_IMAGE_OPTIMIZE);
         }
         if (isset($this->_helper->session->imageQuality)) {
             Tools_Image_Tools::optimizeOriginalImage($fileInfo['tmp_name'], $savePath, $this->_helper->session->imageQuality);
         }
         return array('error' => $status !== true, 'result' => $status);
     }
     return array('error' => true, 'result' => $this->_uploadHandler->getMessages());
 }
开发者ID:PavloKovalov,项目名称:seotoaster,代码行数:62,代码来源:UploadController.php


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