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;