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; }