From 73e3eb9455310e012ffd9b7b15af86650a41753f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 23 Sep 2016 16:22:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4File=E7=B1=BB=E7=9A=84md5?= =?UTF-8?q?=E5=92=8Csha1=E6=96=B9=E6=B3=95=20=E6=94=B9=E4=B8=BAhash?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20=E6=94=AF=E6=8C=81=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E7=9A=84=E6=95=A3=E5=88=97=E5=80=BC=E7=B1=BB=E5=9E=8B=E7=94=9F?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/File.php | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/library/think/File.php b/library/think/File.php index 7095d6b5..85f597e2 100644 --- a/library/think/File.php +++ b/library/think/File.php @@ -95,27 +95,15 @@ class File extends SplFileObject } /** - * 获取文件的md5散列值 - * @return $this + * 获取文件的哈希散列值 + * @return $string */ - public function md5() + public function hash($type = 'sha1') { - if (!isset($this->hash['md5'])) { - $this->hash['md5'] = md5_file($this->filename); + if (!isset($this->hash[$type])) { + $this->hash[$type] = hash_file($type, $this->filename); } - return $this->hash['md5']; - } - - /** - * 获取文件的sha1散列值 - * @return $this - */ - public function sha1() - { - if (!isset($this->hash['sha1'])) { - $this->hash['sha1'] = sha1_file($this->filename); - } - return $this->hash['sha1']; + return $this->hash[$type]; } /**