改进File类 支持闭包规则 参数为当前的文件对象

This commit is contained in:
thinkphp
2016-05-18 15:43:16 +08:00
parent 690839ddc9
commit 2af19639cb

View File

@@ -120,18 +120,18 @@ class File extends SplFileObject
if (true === $savename) {
// 自动生成文件名
if ($this->rule instanceof \Closure) {
$savename = call_user_func_array($this->rule, [$this->getFilename()]);
$savename = call_user_func_array($this->rule, [$this]);
} else {
switch ($this->rule) {
case 'uniqid':
$savename = uniqid();
break;
case 'md5':
$md5 = md5_file($this->getFilename());
$md5 = md5_file($this->getRealPath());
$savename = substr($md5, 0, 2) . DS . substr($md5, 2);
break;
case 'sha1':
$sha1 = sha1_file($this->getFilename());
$sha1 = sha1_file($this->getRealPath());
$savename = substr($sha1, 0, 2) . DS . substr($sha1, 2);
break;
case 'date':