homepage Welcome to WebmasterWorld Guest from 23.23.8.131
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Auto Downloading a remote mp3 file
psl101



 
Msg#: 4463088 posted 7:51 pm on Jun 8, 2012 (gmt 0)

Hello,

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
<?php
$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)
{
die('Haxor');
};
$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);
readfile($filename);
}
else
{
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?

 

coopster

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



 
Msg#: 4463088 posted 2:22 pm on Jun 12, 2012 (gmt 0)

Redirect the user to the resource on the other server?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved