From fb188291d5c550c0741f0bbd04c53dabee69efe8 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 14 Jun 2016 12:53:45 +0800 Subject: [PATCH] =?UTF-8?q?File=E7=B1=BB=E6=94=B9=E8=BF=9B=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/File.php | 14 +++++++++++--- library/think/Input.php | 12 ++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/library/think/File.php b/library/think/File.php index 9ce8f36e..e9111235 100644 --- a/library/think/File.php +++ b/library/think/File.php @@ -22,14 +22,17 @@ class File extends SplFileObject private $error = ''; // 文件上传命名规则 protected $rule = 'date'; + // 单元测试 + protected $isTest; // 上传文件信息 protected $info; - public function __construct($filename, $info = []) + public function __construct($filename, $info = [],$isTest=false) { parent::__construct($filename); - $this->info = $info; + $this->info = $info; + $this->isTest = $isTest; } /** @@ -88,6 +91,9 @@ class File extends SplFileObject */ public function isValid() { + if($this->isTest){ + return is_file($this->getRealPath()); + } return is_uploaded_file($this->getRealPath()); } @@ -122,7 +128,9 @@ class File extends SplFileObject } /* 移动文件 */ - if (!move_uploaded_file($this->getRealPath(), $path . $savename)) { + if($this->isTest){ + rename($this->getRealPath(),$path.$savename); + } elseif (!move_uploaded_file($this->getRealPath(), $path . $savename)) { $this->error = '文件上传保存错误!'; return false; } diff --git a/library/think/Input.php b/library/think/Input.php index 8bb5334d..21953722 100644 --- a/library/think/Input.php +++ b/library/think/Input.php @@ -241,11 +241,19 @@ class Input if (empty($val['tmp_name'])) { continue; } - $item[$key] = new File($val['tmp_name'], $val); + if($val instanceof File){ + $item[$key] = $val; + }else{ + $item[$key] = new File($val['tmp_name'], $val); + } } return $item; } elseif (isset($array[$name])) { - return new File($array[$name]['tmp_name'], $array[$name]); + if($array[$name] instanceof File){ + return $array[$name]; + }else{ + return new File($array[$name]['tmp_name'], $array[$name]); + } } } return null;