Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Auto Downloading a remote mp3 file



7:51 pm on Jun 8, 2012 (gmt 0)


I want to force the user to download a certain MP3 file instead of it playing in the browser.
The problem is, my MP3 files are stored remotely and on different servers. I own a website (not open yet) that allows users to download songs. To keep out of problems with the music industry and whatnot, I am just searching for the files and linking to them on my site. I found this code a while back
$filename = $_GET['file'];
if (isset($filename))
// Prevents someone from trying to access something that is not in the same directory as this script
if(substr_count($filename,"/") > 0)
$len = filesize($filename);
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: public');
header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.$len);
die('No file specified.');

The problem with it was that the files need to be in the same directory as this script and, as i said before, mine are all over the place in different servers.

I am just trying to stay away from the right click > save as stuff.

Is there any way that I could do this with files not on my server?


2:22 pm on Jun 12, 2012 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Redirect the user to the resource on the other server?

Featured Threads

Hot Threads This Week

Hot Threads This Month