From cfda858d87eb4841bcf3ecdf94a898cefa121b35 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Thu, 31 Oct 2024 23:07:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=9B=AE=E5=BD=95=E6=8B=BC=E9=94=99?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/IndexController.php | 6 +++--- app/Module/Base.php | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index 88b1ba86f..5841e2e4d 100755 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -237,13 +237,13 @@ class IndexController extends InvokeController if (str_ends_with($file, '.yml') || str_ends_with($file, '.yaml') || str_ends_with($file, '.blockmap')) { continue; } - $fileName = Base::leftDelete($file, $dirPath); + $fileName = basename($file, $dirPath); $fileSize = filesize($file); $files[] = [ - 'name' => substr($fileName, 1), + 'name' => $fileName, 'time' => date("Y-m-d H:i:s", filemtime($file)), 'size' => $fileSize > 0 ? Base::readableBytes($fileSize) : 0, - 'url' => Base::fillUrl($path . $fileName), + 'url' => Base::fillUrl(Base::joinPath($path, $fileName)), ]; } // diff --git a/app/Module/Base.php b/app/Module/Base.php index 75957586e..86f4aabe7 100755 --- a/app/Module/Base.php +++ b/app/Module/Base.php @@ -2671,10 +2671,14 @@ class Base */ public static function joinPath(...$segments) { - $trimmedSegments = array_map(function ($segment) { + if (count($segments) === 0) { + return ""; + } + $array = array_map(function ($segment) { return trim($segment, DIRECTORY_SEPARATOR); }, $segments); - return implode(DIRECTORY_SEPARATOR, $trimmedSegments); + $prefix = str_starts_with($segments[0], DIRECTORY_SEPARATOR) ? DIRECTORY_SEPARATOR : ""; + return $prefix . implode(DIRECTORY_SEPARATOR, $array); } /**