When downloading certain files, you may find that the filename is truncated up to the first space. Thus, a link to download the file “My music.mp3” produces a save dialog containing “My” as the filename. This is a case of the website incorrectly sending the filename, and the browser coping as best it can.

if the file name contains a quote or spaces; then you have to escape that quote or spaces.

So you can use following code for download mp3 file for the solve this issue.

header(‘Content-Disposition: attachment; filename=”‘ . str_replace(‘”‘, ‘\”‘, $fileName) . ‘”‘);

downlaod.php file:


 // $audioFile = "Maid with the Flaxen Hair.mp3";
 $fileName = $_GET['id'];
 // Fetch the file info.
 $filePath = '../uploads/music/' . $fileName;

 if(file_exists($filePath)) {
 $fileName = basename($filePath);
 $fileSize = filesize($filePath);

 // Output headers.
 header("Cache-Control: private");
 header("Content-Type: application/force-download");
 header("Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3");
 header("Content-Length: ".$fileSize);
// header("Content-Disposition: attachment; filename=".$fileName);
 header('Content-Disposition: attachment; filename="' . str_replace('"', '\"', $fileName) . '"');

 // Output file.
 readfile ($filePath);
 else {
 die('The provided file path is not valid.');


html file:

 <a href="http://localhost/musiclib/include/download.php?id=my music.mp3"> Download</a>