diff --git a/app/Filament/Server/Resources/FileResource/Pages/ListFiles.php b/app/Filament/Server/Resources/FileResource/Pages/ListFiles.php index e118d1bb2..edc233d2a 100644 --- a/app/Filament/Server/Resources/FileResource/Pages/ListFiles.php +++ b/app/Filament/Server/Resources/FileResource/Pages/ListFiles.php @@ -196,7 +196,7 @@ class ListFiles extends ListRecords ->content(fn (Get $get, File $file) => resolve_path('./' . join_paths($this->path, $get('location') ?? '/', $file->name))), ]) ->action(function ($data, File $file) { - $location = rtrim($data['location'], '/'); + $location = $data['location']; $files = [['to' => join_paths($location, $file->name), 'from' => $file->name]]; $this->getDaemonFileRepository()->renameFiles($this->path, $files); @@ -356,7 +356,7 @@ class ListFiles extends ListRecords ->content(fn (Get $get) => resolve_path('./' . join_paths($this->path, $get('location') ?? ''))), ]) ->action(function (Collection $files, $data) { - $location = rtrim($data['location'], '/'); + $location = $data['location']; $files = $files->map(fn ($file) => ['to' => join_paths($location, $file['name']), 'from' => $file['name']])->toArray(); $this->getDaemonFileRepository()->renameFiles($this->path, $files); diff --git a/app/helpers.php b/app/helpers.php index 88e309f78..76ae880ff 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -52,11 +52,14 @@ if (!function_exists('convert_bytes_to_readable')) { if (!function_exists('join_paths')) { function join_paths(string $base, string ...$paths): string { - if ($base === '/') { - return str_replace('//', '', implode('/', $paths)); + $paths = array_filter($paths, fn (string $path) => strlen($path) > 0); + $paths = array_map(fn (string $path) => trim($path, '/'), $paths); + + if (empty($base) || $base === '/') { + return implode('/', $paths); } - return str_replace('//', '', $base . '/' . implode('/', $paths)); + return $base . '/' . implode('/', $paths); } }