兼容软连接目录设置

This commit is contained in:
jqh 2020-07-13 14:43:29 +08:00
parent d65ff46fef
commit 9f9bf0af6c

View File

@ -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);