Skip to content

Commit e8786d1

Browse files
mathieudzandig
authored andcommitted
Fix empty file inputs in Symfony 4.1 (#116)
Symfony 4.1 fails on uploaded files that are null: they must be array or UploadedFile. UploadedFile can only be used for actual files. Solution is to pass the uploaded file as array instead. The array cannot be passed for actual uploaded files because Symfony will not trust the files because they were not created by PHP core. A better solution would be to let Symfony accept null files (see implementation of FileBag).
1 parent 81b1da6 commit e8786d1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Diff for: Bridges/HttpKernel.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,13 @@ protected function mapRequest(ServerRequestInterface $psrRequest)
159159
$this->tempFiles[] = $tmpname;
160160

161161
if (UPLOAD_ERR_NO_FILE == $file->getError()) {
162-
$file = null;
162+
$file = [
163+
'error' => $file->getError(),
164+
'name' => $file->getClientFilename(),
165+
'size' => $file->getSize(),
166+
'tmp_name' => $tmpname,
167+
'type' => $file->getClientMediaType()
168+
];
163169
} else {
164170
if (UPLOAD_ERR_OK == $file->getError()) {
165171
file_put_contents($tmpname, (string)$file->getStream());

0 commit comments

Comments
 (0)