Click here to Skip to main content
15,743,541 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an image on a web page when you click on it, it's suppose to download an mp3, instead it's downloading the mp3.php script file, how can I get it to download the file? Here is the script followed by whats on the page.

PHP
$mp3 = $_GET['mp3'];
$file = '/Tunedoggie/Songs/'.$mp3;

if(ini_get('zlib.output_compression')) {
 ini_set('zlib.output_compression', 'Off');
}

if ( file_exists($file) ) {
 header("Pragma: public");
 header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
 header("Cache-Control: private",false);
 header("Content-Type: application/mp3");
 header('Content-Disposition: attachment; filename="'.$mp3.'"');
 header("Content-Transfer-Encoding: binary");
 header("Content-Length: ".@filesize($file));
 set_time_limit(0);
 @readfile($file) OR die("<html><body OnLoad=\"javascript: alert('Unable to read file!');history.back();\" bgcolor=\"#F0F0F0\"></body></html>");
 exit;
} else {
 die("<html><body OnLoad=\"javascript: alert('File not found!');history.back();\" bgcolor=\"#F0F0F0\"></body></html>");
}

?>


XML
</p>
<p><a href="mp3.php?mp3=Oh No No.mp3"><img src="Dan.jpg" border ="0" alt="Alt Tag Goes Here"></a></p>
Posted
Updated 23-Aug-11 16:15pm
v4
Comments
Member 7766180 23-Aug-11 18:08pm    
When I change it to this, the song plays. Not what I want either. Just want to have the download file manager open and download the file.

1 solution

Change the Content-Type header to application/octet-stream
 
Share this answer
 
Comments
Member 7766180 24-Aug-11 11:11am    
No didn't work, says file not found....I did a work around and changed the mp3 to a zip file and did a link, that works but the problem stil remains if I want to do an actual mp3 file as opposed to a zip.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900