From 4a3ddd43535361b5b59ad1e144db19f4034454d4 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 10 May 2016 10:49:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BInput=E7=B1=BB=E5=92=8Creques?= =?UTF-8?q?t=E7=B1=BB=E7=9A=84file=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Input.php | 16 +++++++++------- library/think/Request.php | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/library/think/Input.php b/library/think/Input.php index f41555df..6ecd82de 100644 --- a/library/think/Input.php +++ b/library/think/Input.php @@ -209,15 +209,17 @@ class Input /** * 获取$_FILES * @param string $name 数据名称 + * @param array $files 上传文件 * @return \think\File|array */ - public static function file($name = '') + public static function file($name = '', $files = []) { - if (!empty($_FILES)) { + $files = $files ?: (isset($_FILES) ? $_FILES : []); + if (!empty($files)) { if ('' === $name) { // 获取全部文件 $file = []; - foreach ($_FILES as $name => $val) { + foreach ($files as $name => $val) { if (empty($val['tmp_name'])) { continue; } @@ -230,15 +232,15 @@ class Input } } return $file; - } elseif (!empty($_FILES[$name]['tmp_name'])) { - if (is_array($_FILES[$name]['tmp_name'])) { + } elseif (!empty($files[$name]['tmp_name'])) { + if (is_array($files[$name]['tmp_name'])) { $file = []; - foreach ($_FILES[$name]['tmp_name'] as $item) { + foreach ($files[$name]['tmp_name'] as $item) { $file[] = new File($item); } return $file; } else { - return new File($_FILES[$name]['tmp_name']); + return new File($files[$name]['tmp_name']); } } } diff --git a/library/think/Request.php b/library/think/Request.php index 4c906313..10ac4b91 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -445,7 +445,7 @@ class Request */ public function file($name = '') { - return Input::data($this->file ?: $_FILES, $name); + return Input::file($name, $this->file ?: $_FILES); } /**