From 0b96964fea52fbd7c412664be7c1fa5dd5be52c4 Mon Sep 17 00:00:00 2001 From: xidear Date: Thu, 25 Nov 2021 14:29:40 +0800 Subject: [PATCH] Update Request.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 如果上传文件不按套路出牌,表单内file的名称命名方式为image[2],image[6],image[5]这种不是从0开始,没有顺序的数组,会500报错 --- src/think/Request.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/think/Request.php b/src/think/Request.php index 1c15f63619..f374543f15 100644 --- a/src/think/Request.php +++ b/src/think/Request.php @@ -1177,10 +1177,12 @@ protected function dealUploadFile(array $files, string $name): array $keys = array_keys($file); $count = count($file['name']); - for ($i = 0; $i < $count; $i++) { - if ($file['error'][$i] > 0) { + + //for ($i = 0; $i < $count; $i++) { + foreach ($file['name'] as $tempKey=>$tempValue){ + if ($file['error'][$tempKey] > 0) { if ($name == $key) { - $this->throwUploadFileError($file['error'][$i]); + $this->throwUploadFileError($file['error'][$tempKey]); } else { continue; } @@ -1189,7 +1191,7 @@ protected function dealUploadFile(array $files, string $name): array $temp['key'] = $key; foreach ($keys as $_key) { - $temp[$_key] = $file[$_key][$i]; + $temp[$_key] = $file[$_key][$tempKey]; } $item[] = new UploadedFile($temp['tmp_name'], $temp['name'], $temp['type'], $temp['error']);