How can rawurlencode help in dealing with spaces in file names in PHP?

When dealing with file names that contain spaces in PHP, using rawurlencode can help encode the spaces as "%20" to ensure proper handling of the file names in URLs. This prevents any issues that may arise from spaces in file names causing errors or broken links.

$filename = "my file.txt";
$encoded_filename = rawurlencode($filename);
echo $encoded_filename; // Output: my%20file.txt