$path = '/var/www/example'; if (GeneralUtility::validPathStr($path)) { // do something with the path } else { // handle invalid path }
$path = '../uploads/../images/avatar.jpg'; $cleanedPath = GeneralUtility::validPathStr($path, true);In this example, the string `../uploads/../images/avatar.jpg` is sanitized to remove any potentially malicious characters or sequences. The function's second parameter is set to true to indicate that the function should perform sanitization. The sanitized path is then returned by the function and can be used safely in file operations. This function is part of the TYPO3 CMS Core package.