Skip to content

Commit

Permalink
replace/emulate $_FILES
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Sep 26, 2023
1 parent d2d7a65 commit 949c930
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Form/Control/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,21 @@ public function onUpload(\Closure $fx): void
$postFiles = [];
for ($i = 0;; ++$i) {
$k = 'file' . ($i > 0 ? '-' . $i : '');
if (!isset($_FILES[$k])) {
$uploadFile = $this->getApp()->tryGetRequestUploadedFile($k);
if ($uploadFile === null) {
break;
}

$postFile = $_FILES[$k];
if ($postFile['error'] !== 0) {
// unset all details on upload error
$postFile = array_intersect_key($postFile, array_flip(['error', 'name']));
$postFile = [
'name' => $uploadFile->getClientFilename(),
'error' => $uploadFile->getError(),
];
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 949c930

Please sign in to comment.