What is the best practice for handling file names with spaces during download in PHP?

When handling file names with spaces during download in PHP, it is important to properly encode the file name to ensure that it is correctly interpreted by the browser. This can be done by using the `urlencode()` function to encode the file name before setting it as the download filename header.

$filename = "my file with spaces.txt";

header("Content-Disposition: attachment; filename=\"" . urlencode($filename) . "\"");