What are the best practices for handling file names like "." and ".." in PHP scripts?

When handling file names like "." and ".." in PHP scripts, it is important to filter out these special directory symbols to prevent any unexpected behavior or security vulnerabilities. One way to handle this is by using the basename() function to extract the base name of the file path, which will exclude any directory symbols.

$file_path = './path/to/..file.txt';
$base_name = basename($file_path);
echo $base_name; // Outputs: file.txt