private function rejectAbsoluteAndDotPaths(string $filePath) : string
{
if (0 === strpos($filePath, '/')) {
// throw: absolute path - not allowed
}
$pathSegments = explode('/', $filePath);
foreach ($pathSegments as $pathSegment) {
if (in_array($pathSegment, ['', '.', '..'], true)) {
// throw: relative path traversal not allowed
}
}
return $filePath;
}