What is the best practice for setting the filename in the Content-Disposition header for file downloads in PHP?

When setting the filename in the Content-Disposition header for file downloads in PHP, it is best practice to sanitize the filename to prevent any potential security risks, such as directory traversal attacks. One way to do this is by using the `basename()` function to extract the filename from the path and then using `urlencode()` to encode any special characters.

// Get the filename from the path
$filename = basename($file_path);

// Encode the filename to handle special characters
$encoded_filename = urlencode($filename);

// Set the Content-Disposition header with the encoded filename
header("Content-Disposition: attachment; filename=\"" . $encoded_filename . "\"");