What is the best practice for concatenating variables to create a file path in PHP?

When concatenating variables to create a file path in PHP, it is best practice to use the `DIRECTORY_SEPARATOR` constant to ensure cross-platform compatibility. This constant represents the directory separator used by the operating system, so your file paths will work correctly on both Windows and Unix-based systems. Additionally, it is recommended to sanitize user input to prevent directory traversal attacks.

// Example of concatenating variables to create a file path in PHP
$directory = 'uploads';
$filename = 'example.txt';

// Using DIRECTORY_SEPARATOR constant for cross-platform compatibility
$file_path = $directory . DIRECTORY_SEPARATOR . $filename;

// Sanitize user input to prevent directory traversal attacks
$file_path = realpath($file_path);

echo $file_path;