From 3e437d96fab9e07137627853e631128137b25684 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 25 Jul 2016 14:20:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BFile=E7=B1=BB=E7=9A=84move?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E7=9A=84=E8=BF=94=E5=9B=9E=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=20=E6=94=B9=E4=B8=BA=E8=BF=94=E5=9B=9E=20File=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E5=AE=9E=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/File.php | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/library/think/File.php b/library/think/File.php index 074a3a59..9dc81a2c 100644 --- a/library/think/File.php +++ b/library/think/File.php @@ -76,11 +76,22 @@ class File extends SplFileObject * 获取上传文件的文件名 * @return string */ - public function saveName() + public function getSaveName() { return $this->saveName; } + /** + * 设置上传文件的保存文件名 + * @param string $saveName + * @return $this + */ + public function setSaveName($saveName) + { + $this->saveName = $saveName; + return $this; + } + /** * 检查目录是否可写 * @param string $path 目录 @@ -194,7 +205,6 @@ class File extends SplFileObject if (!in_array($extension, $ext)) { return false; } - return true; } @@ -273,8 +283,8 @@ class File extends SplFileObject } $path = rtrim($path, DS) . DS; // 文件保存命名规则 - $this->saveName = $this->getSaveName($savename); - $filename = $path . $this->saveName; + $saveName = $this->buildSaveName($savename); + $filename = $path . $saveName; // 检测目录 if (false === $this->checkPath(dirname($filename))) { @@ -294,8 +304,10 @@ class File extends SplFileObject $this->error = '文件上传保存错误!'; return false; } - - return new SplFileInfo($filename); + // 返回 File对象实例 + $file = new self($filename); + $file->setSaveName($saveName); + return $file; } /** @@ -303,7 +315,7 @@ class File extends SplFileObject * @param string|bool $savename 保存的文件名 默认自动生成 * @return string */ - protected function getSaveName($savename) + protected function buildSaveName($savename) { if (true === $savename) { // 自动生成文件名