From 8e58662b05007a9c4995060b7a94a2b5b39b9f29 Mon Sep 17 00:00:00 2001 From: filesite Date: Thu, 21 Apr 2022 07:00:53 +0800 Subject: [PATCH] improve function getScanningLevel --- lib/DirScanner.php | 12 +++++++----- themes/googleimage/views/site/index.php | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/DirScanner.php b/lib/DirScanner.php index 6908d61..461db07 100644 --- a/lib/DirScanner.php +++ b/lib/DirScanner.php @@ -200,14 +200,16 @@ Class DirScanner { } //根据路径和根目录获取当前扫描的目录深度 - private function getScanningLevel($rootDir, $dirname) { + private function getScanningLevel($rootDir, $dir) { $level = 0; - if ($dirname == $rootDir) { + $rootDir = realpath($rootDir); + $dir = realpath($dir); + + if ($dir == $rootDir) { $level = 1; }else { - $dirname = preg_replace('/\/$/', '', $dirname); - $dirs = explode('/', str_replace($rootDir, '', $dirname)); + $dirs = explode('/', str_replace($rootDir, '', $dir)); $level = count($dirs); } @@ -467,7 +469,7 @@ Class DirScanner { if (empty($this->rootDir)) { $this->rootDir = realpath($dir); } - $this->scanningDirLevel = $this->getScanningLevel($this->rootDir, realpath($dir)); + $this->scanningDirLevel = $this->getScanningLevel($this->rootDir, $dir); $nextLevels = $levels - $this->scanningDirLevel; $files = scandir($dir); diff --git a/themes/googleimage/views/site/index.php b/themes/googleimage/views/site/index.php index 6deec1e..1a2331e 100644 --- a/themes/googleimage/views/site/index.php +++ b/themes/googleimage/views/site/index.php @@ -20,7 +20,7 @@ eof;