From b30db5c7541161c97e873523d27cb77c03ab0b6f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 25 Sep 2016 18:38:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BFile=E7=B1=BBbuildSaveName?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E6=94=AF=E6=8C=81=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E7=9A=84=E5=93=88=E5=B8=8C=E8=A7=84=E5=88=99=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/File.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/library/think/File.php b/library/think/File.php index 85f597e2..970063b2 100644 --- a/library/think/File.php +++ b/library/think/File.php @@ -344,19 +344,18 @@ class File extends SplFileObject $savename = call_user_func_array($this->rule, [$this]); } else { switch ($this->rule) { - case 'md5': - $md5 = md5_file($this->filename); - $savename = substr($md5, 0, 2) . DS . substr($md5, 2); - break; - case 'sha1': - $sha1 = sha1_file($this->filename); - $savename = substr($sha1, 0, 2) . DS . substr($sha1, 2); - break; case 'date': $savename = date('Ymd') . DS . md5(microtime(true)); break; default: - $savename = call_user_func($this->rule); + if (in_array($this->rule, hash_algos())) { + $hash = $this->hash($this->rule); + $savename = substr($hash, 0, 2) . DS . substr($hash, 2); + } elseif (is_callable($this->rule)) { + $savename = call_user_func($this->rule); + } else { + $savename = date('Ymd') . DS . md5(microtime(true)); + } } } } elseif ('' === $savename) {