當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ServerRequestInterface::getUploadedFiles方法代碼示例

本文整理匯總了PHP中Psr\Http\Message\ServerRequestInterface::getUploadedFiles方法的典型用法代碼示例。如果您正苦於以下問題:PHP ServerRequestInterface::getUploadedFiles方法的具體用法?PHP ServerRequestInterface::getUploadedFiles怎麽用?PHP ServerRequestInterface::getUploadedFiles使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Psr\Http\Message\ServerRequestInterface的用法示例。


在下文中一共展示了ServerRequestInterface::getUploadedFiles方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 /**
  * @param ServerRequestInterface $request
  * @param RouterInterface $router
  */
 public function __construct(ServerRequestInterface $request, RouterInterface $router)
 {
     $this->request = $request;
     parent::__construct($this);
     $this->parameters = $this->parseIncomingParams();
     $this->parameters = array_merge($this->parameters, $this->request->getParsedBody(), $this->getParsedAttributes($request, $router), $this->getQueryParams(), $this->request->getUploadedFiles());
     $this->parsedBody = array_merge(parent::getParsedBody(), $this->parameters);
 }
開發者ID:atasciuc,項目名稱:zend-expressive-validation,代碼行數:12,代碼來源:RequestValidator.php

示例2: data

 /**
  * {@inheritdoc}
  */
 public function data(ServerRequestInterface $request, Document $document)
 {
     $this->assertAdmin($request->getAttribute('actor'));
     $file = array_get($request->getUploadedFiles(), 'favicon');
     $tmpFile = tempnam($this->app->storagePath() . '/tmp', 'favicon');
     $file->moveTo($tmpFile);
     $extension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
     if ($extension !== 'ico') {
         $manager = new ImageManager();
         $encodedImage = $manager->make($tmpFile)->resize(64, 64, function ($constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         })->encode('png');
         file_put_contents($tmpFile, $encodedImage);
         $extension = 'png';
     }
     $mount = new MountManager(['source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => new Filesystem(new Local($this->app->publicPath() . '/assets'))]);
     if (($path = $this->settings->get('favicon_path')) && $mount->has($file = "target://{$path}")) {
         $mount->delete($file);
     }
     $uploadName = 'favicon-' . Str::lower(Str::quickRandom(8)) . '.' . $extension;
     $mount->move('source://' . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$uploadName}");
     $this->settings->set('favicon_path', $uploadName);
     return parent::data($request, $document);
 }
開發者ID:flarum,項目名稱:core,代碼行數:28,代碼來源:UploadFaviconController.php

示例3: data

 /**
  * {@inheritdoc}
  */
 protected function data(ServerRequestInterface $request, Document $document)
 {
     $id = array_get($request->getQueryParams(), 'id');
     $actor = $request->getAttribute('actor');
     $file = array_get($request->getUploadedFiles(), 'avatar');
     return $this->bus->dispatch(new UploadAvatar($id, $file, $actor));
 }
開發者ID:clops,項目名稱:core,代碼行數:10,代碼來源:UploadAvatarController.php

示例4: _extractDataPSR7

 private function _extractDataPSR7(ServerRequestInterface $request = null, $name = '')
 {
     $method = $request->getMethod();
     $queryParams = $request->getQueryParams();
     if ('GET' === $method) {
         if ('' === $name) {
             return $queryParams;
         }
         // Don't submit GET requests if the form's name does not exist
         // in the request
         if (!isset($queryParams[$name])) {
             return;
         }
         return $queryParams[$name];
     }
     $serverParams = $request->getServerParams();
     $uploadedFiles = $request->getUploadedFiles();
     if ('' === $name) {
         return $this->mergeParamsAndUploadedFiles($serverParams, $uploadedFiles);
     }
     if (isset($serverParams[$name]) || isset($uploadedFiles[$name])) {
         $default = null;
         $params = isset($serverParams[$name]) ? $serverParams[$name] : null;
         $files = isset($uploadedFiles[$name]) ? $uploadedFiles[$name] : null;
         return $this->mergeParamsAndUploadedFiles($params, $files);
     }
     // Don't submit the form if it is not present in the request
     return;
 }
開發者ID:pugx,項目名稱:bindto,代碼行數:29,代碼來源:PSR7RequestTrait.php

示例5: convertRequestFromPsr7

 /**
  * Converts a PSR-7 request into an OAuth2 request.
  *
  * @param ServerRequestInterface $psrRequest
  * @return Request
  */
 public static function convertRequestFromPsr7(ServerRequestInterface $psrRequest)
 {
     $headers = [];
     foreach ($psrRequest->getHeaders() as $header => $value) {
         $headers[$header] = implode(';', $value);
     }
     return new Request($psrRequest->getQueryParams(), is_array($psrRequest->getParsedBody()) ? $psrRequest->getParsedBody() : [], $psrRequest->getAttributes(), $psrRequest->getCookieParams(), self::getFiles($psrRequest->getUploadedFiles()), $psrRequest->getServerParams(), $psrRequest->getBody()->__toString(), $headers);
 }
開發者ID:tonis-io,項目名稱:oauth2,代碼行數:14,代碼來源:Util.php

示例6: updateValuesFromRequest

 /**
  * Assign form values from request
  */
 protected function updateValuesFromRequest()
 {
     $data = $this->getRequest()->isPost() ? $this->getRequest()->getPost() : $this->getRequest()->getQuery();
     if (isset($_FILES)) {
         $data = array_merge($data, $this->request->getUploadedFiles());
     }
     $this->setValues($data);
 }
開發者ID:slickframework,項目名稱:form,代碼行數:11,代碼來源:Form.php

示例7: createRequest

 /**
  * {@inheritdoc}
  */
 public function createRequest(ServerRequestInterface $psrRequest)
 {
     $parsedBody = $psrRequest->getParsedBody();
     $parsedBody = is_array($parsedBody) ? $parsedBody : array();
     $request = new Request($psrRequest->getQueryParams(), $parsedBody, $psrRequest->getAttributes(), $psrRequest->getCookieParams(), $this->getFiles($psrRequest->getUploadedFiles()), $psrRequest->getServerParams(), $psrRequest->getBody()->__toString());
     $request->headers->replace($psrRequest->getHeaders());
     return $request;
 }
開發者ID:papillon-cendre,項目名稱:d8,代碼行數:11,代碼來源:HttpFoundationFactory.php

示例8: onPost

 /**
  * @param ServerRequestInterface $request
  * @param ResponseInterface      $response
  * @return ResponseInterface
  */
 public function onPost(ServerRequestInterface $request, ResponseInterface $response)
 {
     /** @var UploadedFile $upload */
     $uploaded = $request->getUploadedFiles();
     $upload = $uploaded['up'][0];
     $viewData = $this->responder->getViewData()->setData('isUploaded', true)->setData('dump', print_r($uploaded, true))->setData('upload', $upload)->setData('error_code', $upload->getError());
     return $this->viewer->__invoke($request, $response, $viewData);
     // callable
 }
開發者ID:asaokamei,項目名稱:slim-tuum,代碼行數:14,代碼來源:UploadController.php

示例9: toZend

 /**
  * Convert a PSR-7 ServerRequest to a Zend\Http server-side request.
  *
  * @param ServerRequestInterface $psr7Request
  * @param bool $shallow Whether or not to convert without body/file
  *     parameters; defaults to false, meaning a fully populated request
  *     is returned.
  * @return Zend\Request
  */
 public static function toZend(ServerRequestInterface $psr7Request, $shallow = false)
 {
     if ($shallow) {
         return new Zend\Request($psr7Request->getMethod(), $psr7Request->getUri(), $psr7Request->getHeaders(), $psr7Request->getCookieParams(), $psr7Request->getQueryParams(), [], [], $psr7Request->getServerParams());
     }
     $zendRequest = new Zend\Request($psr7Request->getMethod(), $psr7Request->getUri(), $psr7Request->getHeaders(), $psr7Request->getCookieParams(), $psr7Request->getQueryParams(), $psr7Request->getParsedBody() ?: [], self::convertUploadedFiles($psr7Request->getUploadedFiles()), $psr7Request->getServerParams());
     $zendRequest->setContent($psr7Request->getBody());
     return $zendRequest;
 }
開發者ID:MidnightDesign,項目名稱:zend-psr7bridge,代碼行數:18,代碼來源:Psr7ServerRequest.php

示例10: resolveSources

 protected function resolveSources(ServerRequestInterface $request)
 {
     $original_data = ['get' => $request->getQueryParams(), 'post' => $request->getParsedBody(), 'file' => $request->getUploadedFiles(), 'cookie' => $request->getCookieParams(), 'uri' => $this->resolveUriSource($request)];
     foreach ($this->param_sources as $item => $source) {
         if (isset($original_data[$source][$item])) {
             $params[$item] = $original_data[$source][$item];
         }
     }
     return $params;
 }
開發者ID:bermlida,項目名稱:module-extension,代碼行數:10,代碼來源:Route.php

示例11: isUpload

 public function isUpload(ServerRequestInterface $request)
 {
     $contentTypes = $request->getHeader('Content-Type');
     foreach ($contentTypes as $contentType) {
         if (false !== strpos($contentType, 'multipart/form-data')) {
             return count($request->getUploadedFiles()) > 0;
         }
     }
     return false;
 }
開發者ID:danielbragaalmeida,項目名稱:extdirect,代碼行數:10,代碼來源:Router.php

示例12: loadFromPsr7

 /**
  * Load the form values from a PSR-7 ServerRequest.
  *
  * @param ServerRequestInterface $request
  *
  * @return self
  */
 public function loadFromPsr7(ServerRequestInterface $request)
 {
     if (strtolower($this->attr('method')) === 'post') {
         $values = $request->getParsedBody();
         $files = $request->getUploadedFiles();
         $values = array_replace_recursive($values, $files);
     } else {
         $values = $request->getQueryParams();
     }
     return $this->load($values);
 }
開發者ID:goBrabus,項目名稱:form-manager,代碼行數:18,代碼來源:Form.php

示例13: __construct

 /**
  * Construct action request.
  *
  * @param \Psr\Http\Message\ServerRequestInterface $request Request to wrap.
  */
 public function __construct(\Psr\Http\Message\ServerRequestInterface $request)
 {
     parent::__construct($request->getBody());
     foreach ($request->getHeaders() as $name => $value) {
         $this->setHeader($name, $value);
     }
     $this->protocolVersion = $request->getProtocolVersion();
     $this->method = $request->getMethod();
     $this->requestTarget = $request->getRequestTarget();
     $this->uri = $request->getUri();
     $this->attributes = $request->getAttributes();
     $this->cookies = $request->getCookieParams();
     $this->data = $request->getParsedBody();
     $this->query = $request->getQueryParams();
     $this->server = $request->getServerParams();
     $this->files = $request->getUploadedFiles();
     if (isset($this->server['SCRIPT_NAME'])) {
         $this->attributes['basePath'] = dirname($this->server['SCRIPT_NAME']);
         $this->attributes['scriptName'] = basename($this->server['SCRIPT_NAME']);
     } else {
         $this->attributes['basePath'] = '/';
         $this->attributes['scriptName'] = 'index.php';
     }
     if (!isset($this->attributes['path'])) {
         $this->attributes['path'] = self::findPath($this);
     }
     if (!isset($this->attributes['rewrite'])) {
         $this->attributes['rewrite'] = false;
     }
     if (!isset($this->attributes['accepts'])) {
         $this->attributes['accepts'] = [];
         if (isset($this->server['HTTP_ACCEPT'])) {
             $contentTypes = explode(',', $this->server['HTTP_ACCEPT']);
             foreach ($contentTypes as $contentType) {
                 $contentType = explode(';', $contentType);
                 $this->attributes['accepts'][] = trim(strtolower($contentType[0]));
             }
         }
     }
     if (!isset($this->attributes['encodings'])) {
         $this->attributes['encodings'] = [];
         if (isset($this->server['HTTP_ACCEPT_ENCODING'])) {
             $acceptEncodings = explode(',', $this->server['HTTP_ACCEPT_ENCODING']);
             foreach ($acceptEncodings as $encoding) {
                 $this->attributes['encodings'][] = trim(strtolower($encoding));
             }
         }
     }
 }
開發者ID:jivoo,項目名稱:http,代碼行數:54,代碼來源:ActionRequest.php

示例14: __invoke

 /**
  * Flatten all input from the request
  *
  * @param ServerRequestInterface $request
  *
  * @return array
  */
 public function __invoke(ServerRequestInterface $request)
 {
     $attrs = $request->getAttributes();
     $body = $request->getParsedBody();
     $cookies = $request->getCookieParams();
     $query = $request->getQueryParams();
     $uploads = $request->getUploadedFiles();
     if (empty($body)) {
         $body = [];
     } elseif (is_object($body)) {
         // Because the parsed body may also be represented as an object,
         // additional parsing is required. This is a bit dirty but works
         // very well for anonymous objects.
         $body = json_decode(json_encode($body), true);
     }
     // Order matters here! Important values go last!
     return array_replace($query, $body, $uploads, $cookies, $attrs);
 }
開發者ID:JasonBusse,項目名稱:rest_scheduler,代碼行數:25,代碼來源:Input.php

示例15: createRequest

 /**
  * {@inheritdoc}
  */
 public function createRequest(ServerRequestInterface $psrRequest)
 {
     $server = array();
     $uri = $psrRequest->getUri();
     if ($uri instanceof UriInterface) {
         $server['SERVER_NAME'] = $uri->getHost();
         $server['SERVER_PORT'] = $uri->getPort();
         $server['REQUEST_URI'] = $uri->getPath();
         $server['QUERY_STRING'] = $uri->getQuery();
     }
     $server['REQUEST_METHOD'] = $psrRequest->getMethod();
     $server = array_replace($server, $psrRequest->getServerParams());
     $parsedBody = $psrRequest->getParsedBody();
     $parsedBody = is_array($parsedBody) ? $parsedBody : array();
     $request = new Request($psrRequest->getQueryParams(), $parsedBody, $psrRequest->getAttributes(), $psrRequest->getCookieParams(), $this->getFiles($psrRequest->getUploadedFiles()), $server, $psrRequest->getBody()->__toString());
     $request->headers->replace($psrRequest->getHeaders());
     return $request;
 }
開發者ID:symfony,項目名稱:psr-http-message-bridge,代碼行數:21,代碼來源:HttpFoundationFactory.php


注:本文中的Psr\Http\Message\ServerRequestInterface::getUploadedFiles方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。