From 580622ca931c0a659dc200febc7d434571b6bd38 Mon Sep 17 00:00:00 2001 From: Mathieu De Zutter Date: Sat, 2 May 2020 14:57:53 +0200 Subject: [PATCH] Fix file upload in Symfony v5 (#169) --- Bridges/HttpKernel.php | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Bridges/HttpKernel.php b/Bridges/HttpKernel.php index d5d5bbc..504d2dd 100644 --- a/Bridges/HttpKernel.php +++ b/Bridges/HttpKernel.php @@ -183,14 +183,27 @@ private function mapFiles(&$files) if (UPLOAD_ERR_OK == $file->getError()) { file_put_contents($tmpname, (string)$file->getStream()); } - $file = new SymfonyFile( - $tmpname, - $file->getClientFilename(), - $file->getClientMediaType(), - $file->getSize(), - $file->getError(), - true - ); + $class = new \ReflectionClass(SymfonyFile::class); + if (count($class->getConstructor()->getParameters()) === 6) { + // Symfony < v4.1 + $file = new SymfonyFile( + $tmpname, + $file->getClientFilename(), + $file->getClientMediaType(), + $file->getSize(), + $file->getError(), + true + ); + } else { + $file = new SymfonyFile( + $tmpname, + $file->getClientFilename(), + $file->getClientMediaType(), + $file->getError(), + true + ); + } + } } }