改进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 (true === $savename) {
// 自动生成文件名 // 自动生成文件名
if ($this->rule instanceof \Closure) { if ($this->rule instanceof \Closure) {
$savename = call_user_func_array($this->rule, [$this->getFilename()]); $savename = call_user_func_array($this->rule, [$this]);
} else { } else {
switch ($this->rule) { switch ($this->rule) {
case 'uniqid': case 'uniqid':
$savename = uniqid(); $savename = uniqid();
break; break;
case 'md5': case 'md5':
$md5 = md5_file($this->getFilename()); $md5 = md5_file($this->getRealPath());
$savename = substr($md5, 0, 2) . DS . substr($md5, 2); $savename = substr($md5, 0, 2) . DS . substr($md5, 2);
break; break;
case 'sha1': case 'sha1':
$sha1 = sha1_file($this->getFilename()); $sha1 = sha1_file($this->getRealPath());
$savename = substr($sha1, 0, 2) . DS . substr($sha1, 2); $savename = substr($sha1, 0, 2) . DS . substr($sha1, 2);
break; break;
case 'date': case 'date':