Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Sep 26, 2023
1 parent ebe1f68 commit 53f400c
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/Form/Control/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 53f400c

Please sign in to comment.