本文整理汇总了PHP中Zend\Http\Request::getFiles方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getFiles方法的具体用法?PHP Request::getFiles怎么用?PHP Request::getFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Request
的用法示例。
在下文中一共展示了Request::getFiles方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fromZend
/**
* Convert a Zend\Http\Response in a PSR-7 response, using zend-diactoros
*
* @param ZendRequest $zendRequest
* @return ServerRequest
*/
public static function fromZend(ZendRequest $zendRequest)
{
$body = new Stream('php://memory', 'wb+');
$body->write($zendRequest->getContent());
$headers = empty($zendRequest->getHeaders()) ? [] : $zendRequest->getHeaders()->toArray();
$query = empty($zendRequest->getQuery()) ? [] : $zendRequest->getQuery()->toArray();
$post = empty($zendRequest->getPost()) ? [] : $zendRequest->getPost()->toArray();
$files = empty($zendRequest->getFiles()) ? [] : $zendRequest->getFiles()->toArray();
$request = new ServerRequest([], self::convertFilesToUploaded($files), $zendRequest->getUriString(), $zendRequest->getMethod(), $body, $headers);
$request = $request->withQueryParams($query);
return $request->withParsedBody($post);
}
示例2: create
public static function create(HttpRequest $request)
{
$queryParams = $request->getQuery()->toArray();
$postParams = $request->getPost()->toArray();
$files = $request->getFiles()->toArray();
$cookies = ($c = $request->getCookie()) ? [$c] : [];
return new OAuth2Request($queryParams, $postParams, [], $cookies, $files, $_SERVER);
}
示例3: 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));
}
示例4: uploadFile
/**
* @param Request $request
* @param int $buildingId
* @return bool
*/
public function uploadFile($request, $buildingId)
{
try {
/** @var \DDD\Dao\ApartmentGroup\BuildingDetails $buildingDetailsDao */
$buildingDetailsDao = $this->getServiceLocator()->get('dao_apartment_group_building_details');
$files = $request->getFiles();
$file = $files['map_attachment'];
$attachmentExtension = pathinfo($file['name'], PATHINFO_EXTENSION);
// file attached
if ($file['error'] !== 4) {
if ($file['error'] !== 0) {
throw new \Exception('File upload failed.');
}
if ($file['size'] > self::ATTACHMENT_SIZE * 1024 * 1024) {
throw new \Exception('File size is too big.');
}
if (in_array($attachmentExtension, ['php', 'phtml', 'html', 'js'])) {
throw new \Exception('Invalid file format.');
}
$folderPath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT . DirectoryStructure::FS_IMAGES_BUILDING . $buildingId . '/map';
if (!is_dir($folderPath)) {
if (!mkdir($folderPath, 0775, true)) {
throw new \Exception('Upload failed. Can\'t create directory.');
}
}
$oldData = $buildingDetailsDao->fetchOne(['apartment_group_id' => $buildingId], ['map_attachment']);
$filename = 'ki_map_' . $buildingId . '_' . time();
$filename = $filename . '.' . $attachmentExtension;
$fullPath = $folderPath . '/' . $filename;
// remove old uploaded file
if ($oldData['map_attachment']) {
$oldFile = $folderPath . '/' . $oldData['map_attachment'];
@unlink($oldFile);
}
Files::moveFile($file['tmp_name'], $fullPath);
$buildingDetailsDao->save(['map_attachment' => $filename], ['apartment_group_id' => $buildingId]);
return true;
}
} catch (\Exception $ex) {
return false;
}
return false;
}
示例5: authenticate
/**
* Attempt to authenticate the current request.
*
* @param Request $request
* @param Response $response
* @param MvcAuthEvent $mvcAuthEvent
* @return false|Identity\IdentityInterface False on failure, IdentityInterface
* otherwise
*/
public function authenticate(Request $request, Response $response, MvcAuthEvent $mvcAuthEvent)
{
$oauth2request = new OAuth2Request($request->getQuery()->toArray(), $request->getPost()->toArray(), [], $request->getCookie() ? $request->getCookie()->getArrayCopy() : [], $request->getFiles() ? $request->getFiles()->toArray() : [], method_exists($request, 'getServer') ? $request->getServer()->toArray() : $_SERVER, $request->getContent(), $request->getHeaders()->toArray());
// Failure to validate
if (!$this->oauth2Server->verifyResourceRequest($oauth2request)) {
$oauth2Response = $this->oauth2Server->getResponse();
$status = $oauth2Response->getStatusCode();
// 401 or 403 mean invalid credentials or unauthorized scopes; report those.
if (in_array($status, [401, 403], true) && null !== $oauth2Response->getParameter('error')) {
return $this->mergeOAuth2Response($status, $response, $oauth2Response);
}
// Merge in any headers; typically sets a WWW-Authenticate header.
$this->mergeOAuth2ResponseHeaders($response, $oauth2Response->getHttpHeaders());
// Otherwise, no credentials were present at all, so we just return a guest identity.
return new Identity\GuestIdentity();
}
$token = $this->oauth2Server->getAccessTokenData($oauth2request);
$identity = new Identity\AuthenticatedIdentity($token);
$identity->setName($token['user_id']);
return $identity;
}
示例6: processFormRequest
/**
* @param Request $request
* @param FormInterface $form
* @param Content $content
*/
private function processFormRequest(Request $request, FormInterface $form, Content $content)
{
if ($request->isPost()) {
$data = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
$this->processFormData($form, $content, $data);
}
}
示例7: hasUploadedFiles
/**
* @param HttpRequest $files
* @return bool
*/
public static function hasUploadedFiles(HttpRequest $request)
{
$files = $request->getFiles()->toArray();
return (bool) ArrayUtils::filterRecursive($files, function ($value) {
return $value && $value !== UPLOAD_ERR_NO_FILE;
}, true);
}