Skip to content

Fix Psr17Factory::createServerRequestFromGlobals() when uploaded files have been moved #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- [#230](https://github.com/php-http/discovery/pull/230) - Add Psr18Client to make it straightforward to use PSR-18
- [#232](https://github.com/php-http/discovery/pull/232) - Allow pinning the preferred implementations in composer.json
- [#233](https://github.com/php-http/discovery/pull/233) - Fix Psr17Factory::createServerRequestFromGlobals() when uploaded files have been moved

## 1.16.0 - 2023-04-26

Expand Down
2 changes: 1 addition & 1 deletion src/Psr17Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ private function normalizeFiles(array $files): array
private function createUploadedFileFromSpec(array $value)
{
if (!is_array($tmpName = $value['tmp_name'])) {
$file = $this->createStreamFromFile($tmpName, 'r');
$file = is_file($tmpName) ? $this->createStreamFromFile($tmpName, 'r') : $this->createStream();

return $this->createUploadedFile($file, $value['size'], $value['error'], $value['name'], $value['type']);
}
Expand Down
7 changes: 5 additions & 2 deletions tests/Psr17FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,14 @@ public function testFromGlobals()
'file' => [
'name' => 'MyFile.txt',
'type' => 'text/plain',
'tmp_name' => 'php://memory',
'tmp_name' => __FILE__,
'error' => UPLOAD_ERR_OK,
'size' => 123,
],
'files' => [
'name' => ['file_0' => ['NestedFile.txt']],
'type' => ['file_0' => ['text/plain']],
'tmp_name' => ['file_0' => ['php://memory']],
'tmp_name' => ['file_0' => ['/not-exists']],
'error' => ['file_0' => [UPLOAD_ERR_OK]],
'size' => ['file_0' => [123]],
],
Expand Down Expand Up @@ -339,5 +339,8 @@ public function testFromGlobals()
];

self::assertEquals($expectedFiles, $server->getUploadedFiles());

self::assertSame('plainfile', $server->getUploadedFiles()['file']->getStream()->getMetadata()['wrapper_type']);
self::assertSame('PHP', $server->getUploadedFiles()['files']['file_0'][0]->getStream()->getMetadata()['wrapper_type']);
}
}