From 64baf5be00c391fcdb3d81a240aae84cfdc96f79 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 26 Jul 2016 11:18:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BFile=E7=B1=BB=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=AF=B9=E4=B8=8A=E4=BC=A0=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/File.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/library/think/File.php b/library/think/File.php index 5457e26c..7095d6b5 100644 --- a/library/think/File.php +++ b/library/think/File.php @@ -297,6 +297,12 @@ class File extends SplFileObject */ public function move($path, $savename = true, $replace = true) { + // 文件上传失败,捕获错误代码 + if (!empty($this->info['error'])) { + $this->error($this->info['error']); + return false; + } + // 检测合法性 if (!$this->isValid()) { $this->error = '非法上传文件'; @@ -374,6 +380,34 @@ class File extends SplFileObject return $savename; } + /** + * 获取错误代码信息 + * @param int $errorNo 错误号 + */ + private function error($errorNo) + { + switch ($errorNo) { + case 1: + case 2: + $this->error = '上传文件大小超过了最大值!'; + break; + case 3: + $this->error = '文件只有部分被上传!'; + break; + case 4: + $this->error = '没有文件被上传!'; + break; + case 6: + $this->error = '找不到临时文件夹!'; + break; + case 7: + $this->error = '文件写入失败!'; + break; + default: + $this->error = '未知上传错误!'; + } + } + /** * 获取错误信息 * @return mixed