From 6210c5abe7198a15eab4b008ae687d7239cdac84 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 25 Jul 2016 18:34:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BFile=E7=B1=BBmove=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E7=9A=84=E8=BF=94=E5=9B=9E=E5=AF=B9=E8=B1=A1=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=8A=E4=BC=A0=E8=A1=A8=E5=8D=95=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=EF=BC=8C=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=95=A3=E5=88=97=E5=80=BC=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/File.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/library/think/File.php b/library/think/File.php index 9dc81a2c..5457e26c 100644 --- a/library/think/File.php +++ b/library/think/File.php @@ -33,6 +33,8 @@ class File extends SplFileObject protected $isTest; // 上传文件信息 protected $info; + // 文件hash信息 + protected $hash = []; public function __construct($filename, $mode = 'r') { @@ -92,6 +94,30 @@ class File extends SplFileObject return $this; } + /** + * 获取文件的md5散列值 + * @return $this + */ + public function md5() + { + if (!isset($this->hash['md5'])) { + $this->hash['md5'] = md5_file($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']; + } + /** * 检查目录是否可写 * @param string $path 目录 @@ -307,6 +333,7 @@ class File extends SplFileObject // 返回 File对象实例 $file = new self($filename); $file->setSaveName($saveName); + $file->setUploadInfo($this->info); return $file; }