function ServerRequestCreator::createUploadedFileFromSpec
Create and return an UploadedFile instance from a $_FILES specification.
If the specification represents an array of values, this method will delegate to normalizeNestedFileSpec() and return that return value.
Parameters
array $value $_FILES struct:
Return value
array|UploadedFileInterface
2 calls to ServerRequestCreator::createUploadedFileFromSpec()
- ServerRequestCreator::normalizeFiles in vendor/
nyholm/ psr7-server/ src/ ServerRequestCreator.php - Return an UploadedFile instance array.
- ServerRequestCreator::normalizeNestedFileSpec in vendor/
nyholm/ psr7-server/ src/ ServerRequestCreator.php - Normalize an array of file specifications.
File
-
vendor/
nyholm/ psr7-server/ src/ ServerRequestCreator.php, line 209
Class
- ServerRequestCreator
- @author Tobias Nyholm <tobias.nyholm@gmail.com> @author Martijn van der Ven <martijn@vanderven.se>
Namespace
Nyholm\Psr7ServerCode
private function createUploadedFileFromSpec(array $value) {
if (\is_array($value['tmp_name'])) {
return $this->normalizeNestedFileSpec($value);
}
if (UPLOAD_ERR_OK !== $value['error']) {
$stream = $this->streamFactory
->createStream();
}
else {
try {
$stream = $this->streamFactory
->createStreamFromFile($value['tmp_name']);
} catch (\RuntimeException $e) {
$stream = $this->streamFactory
->createStream();
}
}
return $this->uploadedFileFactory
->createUploadedFile($stream, (int) $value['size'], (int) $value['error'], $value['name'], $value['type']);
}