From 930e2fcc0b3b21ca8b983aca6a3281afcd34a913 Mon Sep 17 00:00:00 2001 From: Mathieu De Zutter Date: Mon, 30 Jul 2018 22:33:47 +0200 Subject: [PATCH] Fix empty file inputs in Symfony 4.1 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). --- Bridges/HttpKernel.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Bridges/HttpKernel.php b/Bridges/HttpKernel.php index 1177792..6476196 100644 --- a/Bridges/HttpKernel.php +++ b/Bridges/HttpKernel.php @@ -159,7 +159,13 @@ protected function mapRequest(ServerRequestInterface $psrRequest) $this->tempFiles[] = $tmpname; if (UPLOAD_ERR_NO_FILE == $file->getError()) { - $file = null; + $file = [ + 'error' => $file->getError(), + 'name' => $file->getClientFilename(), + 'size' => $file->getSize(), + 'tmp_name' => $tmpname, + 'type' => $file->getClientMediaType() + ]; } else { if (UPLOAD_ERR_OK == $file->getError()) { file_put_contents($tmpname, (string)$file->getStream());