What are the best practices for handling user input of file paths in PHP forms to ensure compatibility across different platforms?

When handling user input of file paths in PHP forms, it's important to sanitize and normalize the input to ensure compatibility across different platforms. One way to achieve this is by using the `realpath()` function to resolve any relative paths and ensure the path is valid. Additionally, you can use `DIRECTORY_SEPARATOR` constant to handle file path separators in a platform-independent way.

// Sanitize and normalize file path input
$userFilePath = isset($_POST['file_path']) ? $_POST['file_path'] : '';
$normalizedPath = realpath($userFilePath);

// Use DIRECTORY_SEPARATOR for platform-independent file path handling
$finalPath = str_replace('/', DIRECTORY_SEPARATOR, $normalizedPath);

// Now $finalPath contains the sanitized and normalized file path