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


PHP Zend_File_Transfer_Adapter_Http::addValidators方法代码示例

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


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

示例1: uploadAction

 public function uploadAction()
 {
     $request = $this->getRequest();
     $table = new Model_DbTable_Sheets();
     $select = $table->select();
     $select->where('id = ?', $request->id);
     $sheet = $table->fetchRow($select);
     if (!$this->view->authenticated || $sheet->user_id != $this->view->identity->id) {
         $this->_redirector->gotoRoute(array(), 'login');
     }
     if ($request->isPost()) {
         $path = UPLOAD_PATH . '/sheets/';
         if (!file_exists($path)) {
             mkdir(str_replace('//', '/', $path), 0755, true);
         }
         $upload = new Zend_File_Transfer_Adapter_Http();
         $upload->setDestination($path);
         $upload->addValidators(array(array('Count', false, 5), array('Size', false, '2MB'), array('Extension', false, array('pdf', 'midi', 'mid'))));
         if ($upload->isValid()) {
             $table = new Model_DbTable_Downloads();
             $pattern = array('/-/', '/_/', '/\\s+/');
             $replace = array(' - ', ' ', ' ');
             foreach ($upload->getFileInfo() as $file => $contents) {
                 $info = pathinfo($contents['name']);
                 $row = $table->createRow();
                 $row->sheet_id = $sheet->id;
                 $row->type = strtolower($info['extension']) == 'pdf' ? 'PDF' : 'MIDI';
                 $title = preg_replace($pattern, $replace, $info['filename']);
                 $row->title = ucwords($title);
                 $row->save();
                 $name = $row->id . ($row->type == 'MIDI' ? '.mid' : '.pdf');
                 $upload->addFilter('Rename', array('target' => $name), $file);
                 $upload->receive($file);
             }
             if ($upload->isReceived()) {
                 return $this->_redirector->gotoRoute(array('controller' => 'sheet', 'id' => $request->id), 'view');
             }
         }
         $this->view->errors = $upload->getMessages();
     }
     $this->view->headTitle('Upload sheet file(s)');
     $this->view->headScript()->appendFile('/js/multifile.js');
     $this->view->headScript()->appendFile('/js/upload.js');
     $this->view->sheetId = $request->id;
 }
开发者ID:hollusion,项目名称:Netons,代码行数:45,代码来源:SheetController.php


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