From 14112f2420855c92d90836b43ba27482622cefc9 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 29 Jul 2016 17:10:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=96=87=E4=BB=B6=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E5=92=8C=E6=97=A5=E5=BF=97=E7=9A=84=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8D=E5=91=BD=E5=90=8D=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/cache/driver/File.php | 22 ++++++++++------------ library/think/log/driver/File.php | 5 +++-- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/library/think/cache/driver/File.php b/library/think/cache/driver/File.php index c356f21c..7f496e7d 100644 --- a/library/think/cache/driver/File.php +++ b/library/think/cache/driver/File.php @@ -69,19 +69,17 @@ class File $name = md5($name); if ($this->options['cache_subdir']) { // 使用子目录 - $dir = ''; - $len = $this->options['path_level']; - for ($i = 0; $i < $len; $i++) { - $dir .= $name{$i} . DS; - } - if (!is_dir($this->options['path'] . $dir)) { - mkdir($this->options['path'] . $dir, 0755, true); - } - $filename = $dir . $this->options['prefix'] . $name . '.php'; - } else { - $filename = $this->options['prefix'] . $name . '.php'; + $name = substr($md5, 0, 2) . DS . substr($md5, 2); } - return $this->options['path'] . $filename; + if ($this->options['prefix']) { + $name = $this->options['prefix'] . DS . $name; + } + $filename = $this->options['path'] . $name . '.php'; + $dir = dirname($filename); + if (!is_dir($dir)) { + mkdir($dir, 0755, true); + } + return $filename; } /** diff --git a/library/think/log/driver/File.php b/library/think/log/driver/File.php index d1d2852d..be6e1d0f 100644 --- a/library/think/log/driver/File.php +++ b/library/think/log/driver/File.php @@ -39,9 +39,10 @@ class File public function save(array $log = []) { $now = date($this->config['time_format']); - $destination = $this->config['path'] . date('y_m_d') . '.log'; + $destination = $this->config['path'] . date('Ym') . DS . date('d') . '.log'; - !is_dir($this->config['path']) && mkdir($this->config['path'], 0755, true); + $path = dirname($destination); + !is_dir($path) && mkdir($path, 0755, true); //检测日志文件大小,超过配置大小则备份日志文件重新生成 if (is_file($destination) && floor($this->config['file_size']) <= filesize($destination)) {