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); } /**