From d04282d92d5cd3be4f11d47cc6c310c03555572b Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 26 Mar 2025 00:07:41 +0100 Subject: [PATCH] fs.php: add concat_path --- inc/functions/fs.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/inc/functions/fs.php b/inc/functions/fs.php index 2d38c384..37901bf0 100644 --- a/inc/functions/fs.php +++ b/inc/functions/fs.php @@ -15,3 +15,17 @@ function move_or_copy_uploaded(string $from, string $to) { } return true; } + +/** + * Concats two paths accounting for directory separators. + */ +function concat_path(string $base, string $other): string { + if ($base[\strlen($base) - 1] === DIRECTORY_SEPARATOR) { + $base = \substr($base, 0, \strlen($base) - 1); + } + if ($other[0] === DIRECTORY_SEPARATOR) { + return $base . $other; + } else { + return $base . DIRECTORY_SEPARATOR . $other; + } +}