What are some best practices for handling file paths and directories in PHP scripts?

When handling file paths and directories in PHP scripts, it is important to use the correct directory separator for the operating system the script is running on. Additionally, it is recommended to use PHP's built-in functions like `dirname()` and `realpath()` to manipulate and validate file paths. Finally, always sanitize user input to prevent directory traversal attacks.

// Example of using realpath() to get the absolute path of a file
$filePath = 'uploads/file.txt';
$absolutePath = realpath($filePath);
if ($absolutePath !== false) {
    echo "Absolute path: " . $absolutePath;
} else {
    echo "Invalid file path";
}