From 9f9bf0af6c1beb271e03322010505d54d7ed63a8 Mon Sep 17 00:00:00 2001 From: jqh <841324345@qq.com> Date: Mon, 13 Jul 2020 14:43:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E8=BD=AF=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/LogViewer.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/LogViewer.php b/src/LogViewer.php index 53d256f..9d7575b 100644 --- a/src/LogViewer.php +++ b/src/LogViewer.php @@ -73,12 +73,29 @@ class LogViewer */ public function __construct($basePath, $dir, $file = null) { - $this->basePath = rtrim($basePath, '/'); + $this->basePath = $this->getRealPath(rtrim($basePath, '/')); $this->currentDirectory = $this->formatPath(rtrim($dir, '/')); $this->file = $this->formatPath($file); $this->files = new Filesystem(); } + protected function getRealPath($path) + { + $paths = explode('/', $path); + + $result = ''; + foreach ($paths as $v) { + $result .= $v.'/'; + + $current = rtrim($result, '/'); + if (is_link($current)) { + $result = readlink($current).'/'; + } + } + + return rtrim($result, '/'); + } + protected function formatPath($path) { return str_replace(['../'], '', $path); @@ -165,7 +182,7 @@ class LogViewer return $this->getLogBasePath(); } - return $this->getLogBasePath() . '/' . $this->currentDirectory; + return $this->getLogBasePath().'/'.$this->currentDirectory; } /**