fix: 目录拼错的情况

This commit is contained in:
kuaifan 2024-10-31 23:07:13 +08:00
parent df8fdd56ba
commit cfda858d87
2 changed files with 9 additions and 5 deletions

View File

@ -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)),
];
}
//

View File

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