What are some common troubleshooting steps for resolving PHP download filename issues?

When downloading files with PHP, sometimes the filename of the downloaded file may not be what you expect. This can happen due to incorrect headers being set or special characters in the filename causing issues. To resolve this, you can set the "Content-Disposition" header with the desired filename using the "header()" function in PHP.

<?php
$file = 'example.pdf';
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
?>