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


PHP Request::setFiles方法代码示例

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


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

示例1: testParameterRetrievalDefaultValue

 public function testParameterRetrievalDefaultValue()
 {
     $request = new Request();
     $p = new \Zend\Stdlib\Parameters(array('foo' => 'bar'));
     $request->setQuery($p);
     $request->setPost($p);
     $request->setFiles($p);
     $default = 15;
     $this->assertSame($default, $request->getQuery('baz', $default));
     $this->assertSame($default, $request->getPost('baz', $default));
     $this->assertSame($default, $request->getFiles('baz', $default));
     $this->assertSame($default, $request->getHeaders('baz', $default));
     $this->assertSame($default, $request->getHeader('baz', $default));
 }
开发者ID:rajanlamic,项目名称:IntTest,代码行数:14,代码来源:RequestTest.php

示例2: parseFromStream


//.........这里部分代码省略.........
                     }
                 }
                 if ($filename) {
                     // At this point, we can add the file entry, regardless of error condition
                     $files->set($name, $file);
                 }
             }
             // Is this a boundary end? If so, we're done
             if (preg_match($partBoundaryPatternEnd, $trimmedLine)) {
                 // Met the "end" boundary; time to stop!
                 break;
             }
             // New part to parse!
             $partInProgress = true;
             $inHeader = true;
             $headers = [];
             $header = '';
             continue;
         }
         if (!$partInProgress) {
             // We're not inside a part, so do nothing.
             continue;
         }
         if ($inHeader) {
             if (preg_match('/^\\s*$/s', $line)) {
                 // Headers are done; cleanup
                 $inHeader = false;
                 $content = '';
                 $file = ['error' => UPLOAD_ERR_OK];
                 $tmpFile = false;
                 $lastline = null;
                 // Parse headers
                 $name = $this->getNameFromHeaders($headers);
                 if (!$name) {
                     throw new Exception\InvalidMultipartContentException('Missing Content-Disposition header, or Content-Disposition header does not ' . 'contain a "name" field');
                 }
                 $filename = $this->getFilenameFromHeaders($headers);
                 $mimeType = $this->getMimeTypeFromHeaders($headers);
                 continue;
             }
             if (preg_match('/^(?P<header>[a-z]+[a-z0-9_-]+):\\s*(?P<value>.*)$/i', $trimmedLine, $matches)) {
                 $header = strtoupper($matches['header']);
                 $headers[$header] = $matches['value'];
                 continue;
             }
             if (!$header) {
                 throw new Exception\InvalidMultipartContentException('Malformed or missing MIME part header for multipart content');
             }
             $headers[$header] .= $trimmedLine;
             continue;
         }
         // In the body content...
         // Data only; aggregate.
         if (!$filename) {
             $content .= $line;
             continue;
         }
         // If we've had an error already with the upload, continue parsing
         // to the end of the MIME part
         if ($file['error'] !== UPLOAD_ERR_OK) {
             continue;
         }
         // Create a temporary file handle if we haven't already
         if (!$tmpFile) {
             // Sets the file entry
             $file['name'] = $filename;
             $file['type'] = $mimeType;
             $tmpDir = $this->getUploadTempDir();
             if (empty($tmpDir)) {
                 // Cannot ascertain temporary directory; this is an error
                 $file['error'] = UPLOAD_ERR_NO_TMP_DIR;
                 continue;
             }
             $file['tmp_name'] = tempnam($tmpDir, 'zfc');
             $tmpFile = fopen($file['tmp_name'], 'wb');
             if (false === $tmpFile) {
                 // Cannot open the temporary file for writing; this is an error
                 $file['error'] = UPLOAD_ERR_CANT_WRITE;
                 continue;
             }
         }
         // Off-by-one operation. Last line must be trimmed, so we'll write
         // the lines one iteration behind.
         if (null === $lastline) {
             $lastline = $line;
             continue;
         }
         if (false === fwrite($tmpFile, $lastline)) {
             $file['error'] = UPLOAD_ERR_CANT_WRITE;
             fclose($tmpFile);
             continue;
         }
         $lastline = $line;
     }
     fclose($stream);
     if ($files->count()) {
         $this->request->setFiles($files);
     }
     return $data->toArray();
 }
开发者ID:gstearmit,项目名称:EshopVegeTable,代码行数:101,代码来源:MultipartContentParser.php

示例3: testOnFinishDoesNotRemoveUploadFilesThatHaveBeenMoved

 public function testOnFinishDoesNotRemoveUploadFilesThatHaveBeenMoved()
 {
     $tmpDir = sys_get_temp_dir() . '/' . str_replace('\\', '_', __CLASS__);
     mkdir($tmpDir);
     $tmpFile = tempnam($tmpDir, 'zfc');
     $files = new Parameters(array('test' => array('error' => UPLOAD_ERR_OK, 'name' => 'test.txt', 'type' => 'text/plain', 'tmp_name' => $tmpFile)));
     $request = new Request();
     $request->setFiles($files);
     $event = new MvcEvent();
     $event->setRequest($request);
     $this->listener->onFinish($event);
     $this->assertTrue(file_exists($tmpFile));
     unlink($tmpFile);
     rmdir($tmpDir);
 }
开发者ID:alapini,项目名称:apigility-3hr-tutorial,代码行数:15,代码来源:ContentTypeListenerTest.php

示例4: testMergesFilesArrayIntoDataPriorToValidationWhenFilesArrayIsPopulated

    public function testMergesFilesArrayIntoDataPriorToValidationWhenFilesArrayIsPopulated()
    {
        $validator = $this->getMock('Zend\InputFilter\InputFilterInterface');
        $services = new ServiceManager();
        $services->setService('FooValidator', $validator);

        $listener = new ContentValidationListener(array(
            'Foo' => array('input_filter' => 'FooValidator'),
        ), $services);

        $files = new Parameters(array(
            'foo' => array(
                'name' => 'foo.txt',
                'type' => 'text/plain',
                'size' => 1,
                'tmp_name' => '/tmp/foo.txt',
                'error' => UPLOAD_ERR_OK,
            ),
        ));
        $data = array(
            'bar' => 'baz',
            'quz' => 'quuz',
        );
        $dataContainer = new ParameterDataContainer();
        $dataContainer->setBodyParams($data);

        $request = new HttpRequest();
        $request->setMethod('POST');
        $request->setFiles($files);

        $matches = new RouteMatch(array('controller' => 'Foo'));

        $event   = new MvcEvent();
        $event->setRequest($request);
        $event->setRouteMatch($matches);
        $event->setParam('ZFContentNegotiationParameterData', $dataContainer);

        $validator->expects($this->any())
            ->method('has')
            ->with($this->equalTo('FooValidator'))
            ->will($this->returnValue(true));
        $validator->expects($this->once())
            ->method('setData')
            ->with($this->equalTo(array_merge_recursive($data, $files->toArray())));
        $validator->expects($this->once())
            ->method('isValid')
            ->will($this->returnValue(true));

        $this->assertNull($listener->onRoute($event));
    }
开发者ID:jbarentsen,项目名称:drb,代码行数:50,代码来源:ContentValidationListenerTest.php


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