From 53f400c273c3217f3b0c9b5bcedac8276bcaca54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Tue, 26 Sep 2023 11:53:25 +0200 Subject: [PATCH] simplify --- src/Form/Control/Upload.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Form/Control/Upload.php b/src/Form/Control/Upload.php index 3ac2830a92..653a9d50ab 100644 --- a/src/Form/Control/Upload.php +++ b/src/Form/Control/Upload.php @@ -145,22 +145,21 @@ public function onUpload(\Closure $fx): void $postFiles = []; for ($i = 0;; ++$i) { $k = 'file' . ($i > 0 ? '-' . $i : ''); - if (!$this->getApp()->hasRequestUploadedFile($k)) { + $uploadFile = $this->getApp()->tryGetRequestUploadedFile($k); + if ($uploadFile === null) { break; } - $uploadFile = $this->getApp()->getRequestUploadedFile($k); $postFile = [ 'name' => $uploadFile->getClientFilename(), - 'type' => $uploadFile->getClientMediaType(), - 'tmp_name' => $uploadFile->getError() > 0 ? null : $uploadFile->getStream()->getMetadata('uri'), 'error' => $uploadFile->getError(), - 'size' => $uploadFile->getSize(), ]; - if ($uploadFile->getError() !== 0) { - // unset all details on upload error - $postFile = array_intersect_key($postFile, array_flip(['error', 'name'])); - // TODO add error message https://www.php.net/manual/en/features.file-upload.errors.php + if ($uploadFile->getError() === \UPLOAD_ERR_OK) { + $postFile = array_merge($postFile, [ + 'type' => $uploadFile->getClientMediaType(), + 'tmp_name' => $uploadFile->getStream()->getMetadata('uri'), + 'size' => $uploadFile->getSize(), + ]); } $postFiles[] = $postFile; }