Sfoglia il codice sorgente

https://github.com/walkor/webman/issues/202

walkor 4 anni fa
parent
commit
cddba832f9
1 ha cambiato i file con 15 aggiunte e 6 eliminazioni
  1. 15 6
      Protocols/Http/Request.php

+ 15 - 6
Protocols/Http/Request.php

@@ -560,9 +560,13 @@ class Request
             }
         }
         foreach ($files as $file) {
-            if (isset($file['key'])) {
-                $key = $file['key'];
-                unset($file['key']);
+            $key = $file['key'];
+            unset($file['key']);
+            // Multi files
+            if (\strlen($key) > 2 && \substr($key, -2) == '[]') {
+                $key = \substr($key, 0, -2);
+                $this->_data['files'][$key][] = $file;
+            } else {
                 $this->_data['files'][$key] = $file;
             }
         }
@@ -640,9 +644,14 @@ class Request
     {
         if (isset($this->_data['files'])) {
             \clearstatcache();
-            foreach ($this->_data['files'] as $item) {
-                if (\is_file($item['tmp_name'])) {
-                    \unlink($item['tmp_name']);
+            foreach ($this->_data['files'] as $items) {
+                if (!\is_array(\current($items))) {
+                    $items = [$items];
+                }
+                foreach ($items as $item) {
+                    if (\is_file($item['tmp_name'])) {
+                        \unlink($item['tmp_name']);
+                    }
                 }
             }
         }