In what ways can a PHP script be optimized to handle file server access and path resolution in a cross-platform environment?

When handling file server access and path resolution in a cross-platform environment, it's important to use PHP's built-in functions like `realpath()` to normalize file paths and ensure they are correctly formatted for the operating system being used. Additionally, using the `DIRECTORY_SEPARATOR` constant can help ensure paths are constructed correctly regardless of the platform.

// Normalize file path using realpath() and DIRECTORY_SEPARATOR
$file = 'path/to/file.txt';
$realPath = realpath($file);
if ($realPath) {
    $normalizedPath = str_replace('/', DIRECTORY_SEPARATOR, $realPath);
    echo $normalizedPath;
} else {
    echo 'File not found.';
}