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


PHP FileModel::storeFilename方法代码示例

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


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

示例1: saveAction

 /**
  * Saves the page currently being edited
  */
 public function saveAction()
 {
     try {
         $page = new PageModel(array('pageID' => $this->_getParam('id'), 'depth' => 'page'));
         $lock = $this->lockPage($page, 'edit');
         $attachments = array();
         $auth = Zend_Auth::getInstance();
         $user = DbUserModel::findByUsername($auth->getIdentity());
         $responses = array();
         foreach ($this->_getAllParams() as $key => $value) {
             // if the element's name begins 'qXXX' where X is a digit
             if (preg_match('/^q(\\d+)(.*)$/', $key, $matches)) {
                 $questionID = intval($matches[1]);
                 $remainder = $matches[2];
                 // if the element name consists of *only* 'qXXX' or qXXX_mXXX for multiple select question types
                 if ($remainder == '' || preg_match('/^_m(\\d+)$/', $remainder)) {
                     $q = new QuestionModel(array('questionID' => $questionID));
                     $response = $q->getResponse();
                     if ($response->state == 2) {
                         $this->flash('error', 'You cannot modify a response that has been approved');
                         $this->_redirector->gotoRouteAndExit(array('action' => 'view', 'id' => $page->pageID));
                     }
                     if (strlen($value) > 0) {
                         $responses[$questionID]['value'][] = $value;
                     }
                 } elseif ($remainder == "_addl_mod" && intval($this->_getParam("q{$questionID}_addl_mod"))) {
                     $responses[$questionID]['addl'] = $this->_getParam("q{$questionID}_addl");
                 } elseif ($remainder == "_privateNote_mod" && intval($this->_getParam("q{$questionID}_privateNote_mod"))) {
                     $responses[$questionID]['pNote'] = $this->_getParam("q{$questionID}_privateNote");
                 } elseif ($remainder == '_attachments') {
                     $question = new QuestionModel(array('questionID' => $questionID));
                     foreach ($value as $file) {
                         $fileModel = new FileModel($question);
                         $properties = Spyc::YAMLLoad(PROJECT_PATH . '/tmp/.' . $file);
                         $fileModel->storeFilename(PROJECT_PATH . '/tmp/' . $file, $properties);
                     }
                 } elseif (preg_match('/^_file(\\d+)_delete$/', $remainder, $matches) && $value === 'true') {
                     $question = new QuestionModel(array('questionID' => $questionID));
                     $fileModel = new FileModel($question);
                     $fileModel->delete(intval($matches[1]));
                 }
             }
         }
         foreach ($responses as $questionID => $data) {
             $q = new QuestionModel(array('questionID' => $questionID));
             $response = $q->getResponse();
             if (isset($data['value'])) {
                 $response->responseText = join(',', $data['value']);
             }
             if (isset($data['addl'])) {
                 $response->additionalInfo = $data['addl'];
             }
             if (isset($data['pNote'])) {
                 $response->privateNote = $data['pNote'];
             }
             $response->save($user);
         }
         /* If there are any file uploads that didn't auto-upload before the user saved */
         foreach ($_FILES as $name => $file) {
             if ($file['size'] > 0) {
                 $question = new QuestionModel(array('questionID' => intVal($name)));
                 $fileModel = new FileModel($question);
                 $properties = array('filename' => $file['name'], 'mime' => $file['type']);
                 $fileModel->storeFilename($file['tmp_name'], $properties);
             }
         }
         $page = new PageModel(array('pageID' => $this->_getParam('id'), 'depth' => 'response'));
         $page->save();
         $instance = new InstanceModel(array('instanceID' => $page->instanceID, 'depth' => 'page'));
         $instance->save();
     } catch (Exception $e) {
         $this->view->error = $e->getMessage();
     }
     $this->view->setRenderLayout(false);
 }
开发者ID:humansky,项目名称:qframe,代码行数:78,代码来源:PageController.php

示例2: testFetchObjectIdsByInstance

 public function testFetchObjectIdsByInstance()
 {
     $properties = array('filename' => 'sample.pdf', 'mime' => 'application/pdf');
     $filesNoId = new FileModel(new NoInstanceFoo());
     $filesNoId->storeFilename(TEST_PATH . '/fixtures/sample.pdf', $properties);
     $filesId = new FileModel(new InstanceFoo());
     $filesId->storeFilename(TEST_PATH . '/fixtures/sample.pdf', $properties);
     $objectIds = FileModel::fetchObjectIdsByInstance(1);
     $this->assertTrue(is_array($objectIds));
     $this->assertEquals(count($objectIds), 1);
     $this->assertTrue(isset($objectIds['InstanceFoo']));
     $this->assertTrue(is_array($objectIds['InstanceFoo']));
     $this->assertEquals(count($objectIds['InstanceFoo']), 1);
 }
开发者ID:humansky,项目名称:qframe,代码行数:14,代码来源:FileModelTest.php


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