Medowar před 1 týdnem
rodič
revize
472cc65d78
2 změnil soubory, kde provedl 22 přidání a 2 odebrání
  1. 21 2
      src/storage/fileuploadstore.php
  2. 1 0
      src/storage/jsonstore.php

+ 21 - 2
src/storage/fileuploadstore.php

@@ -107,8 +107,8 @@ final class FileUploadStore
     /** @param array<string, mixed> $files */
     private function pickUploadedFile(array $files, string $fieldKey): ?array
     {
-        $primary = $files[$fieldKey] ?? null;
-        $camera = $files[$fieldKey . '__camera'] ?? null;
+        $primary = $this->extractFirstFile($files[$fieldKey] ?? null);
+        $camera = $this->extractFirstFile($files[$fieldKey . '__camera'] ?? null);
 
         if (is_array($primary) && ((int) ($primary['error'] ?? UPLOAD_ERR_NO_FILE) === UPLOAD_ERR_OK)) {
             return $primary;
@@ -127,6 +127,25 @@ final class FileUploadStore
         return null;
     }
 
+    private function extractFirstFile(mixed $fileArray): ?array
+    {
+        if (!is_array($fileArray)) {
+            return null;
+        }
+        
+        if (isset($fileArray['name']) && is_array($fileArray['name'])) {
+            return [
+                'name' => $fileArray['name'][0] ?? '',
+                'type' => $fileArray['type'][0] ?? '',
+                'tmp_name' => $fileArray['tmp_name'][0] ?? '',
+                'error' => $fileArray['error'][0] ?? UPLOAD_ERR_NO_FILE,
+                'size' => $fileArray['size'][0] ?? 0,
+            ];
+        }
+        
+        return $fileArray;
+    }
+
     private function sanitizeFilename(string $name): string
     {
         $name = str_replace(["\0", '/', '\\'], '', $name);

+ 1 - 0
src/storage/jsonstore.php

@@ -228,6 +228,7 @@ final class JsonStore
         } finally {
             flock($handle, LOCK_UN);
             fclose($handle);
+            @unlink($lockFile);
         }
     }