spires Posted August 16, 2006 Share Posted August 16, 2006 Hi, Does any one know if you can download a mp3 when a page opens? (onLoad etc)I'm am creating a shopping cart that sells MP3s, if i use RIGHT CLICK and SAVE TO DESKTOP, the customer can download as many as they want. Does any one know of a way around this. some kind of function that can read the RIGHT CLICK perhaps?Thanks for your help Quote Link to comment Share on other sites More sharing options...
Jocka Posted August 16, 2006 Share Posted August 16, 2006 you mean to keep them from seeing the link and giving it out? Quote Link to comment Share on other sites More sharing options...
spires Posted August 16, 2006 Author Share Posted August 16, 2006 No, the page itself uses session and a login system, so they cant give the link out. I'm trying to find a way where they cant keep right clicking the track, and downloading as many as they want. I need to find a way where if you click the link it will automaticaly download to their desktop ORlink to a page that has some kind of - onLoad download track to deasktop function.There must be some way of limiting them to only one download?Is there any way of controlling the right click function through php?thanks for any help :DJeff Quote Link to comment Share on other sites More sharing options...
effigy Posted August 16, 2006 Share Posted August 16, 2006 Send them to a link that passes the mp3 over via header. For example:[code]<a href="get_mp3.php?mp3=band-song.mp3">Download</a>[/code]In get_mp3.php, check their information against the database to see if they've already downloaded the file. If not, update the information and use header commands to send the mp3. I'm not sure how to verify that the download was successful though... Quote Link to comment Share on other sites More sharing options...
spires Posted August 16, 2006 Author Share Posted August 16, 2006 Thanks. I have had it before where i send them to another page, but i still have the same problem of getting the mp3 to download automatically. they still have to right click a link to download the file. As far as i can tell, there is no way of downloading without right clicking and saving to desktop. if you just click, it only plays the track. Doesn't download it.any more suggestions please. Quote Link to comment Share on other sites More sharing options...
Jocka Posted August 16, 2006 Share Posted August 16, 2006 umm. try this.http://www.phpfreaks.com/forums/index.php/topic,95433.0.html Quote Link to comment Share on other sites More sharing options...
effigy Posted August 16, 2006 Share Posted August 16, 2006 Left clicking a link can start a download. Here's an example from an old piece of code; I would do some research to make sure this is still the preferred approach.[code] ### $mp3 is the full path to the mp3. $file_size = filesize($mp3); $fp = fopen($mp3, 'r'); $buffer = fread($fp, $file_size); header("Content-type: application/x-octet-stream"); ### You should be able to use the mp3 type here. header("Content-disposition: attachment;filename=".basename($mp3)); header("Content-length: $file_size"); echo $buffer;[/code][b]Update:[/b] Try the link Jocka provided. Quote Link to comment Share on other sites More sharing options...
spires Posted August 16, 2006 Author Share Posted August 16, 2006 Thanks guysI will try all of those out. At least i know i can actually be done now.And i now see what you mean effigy, by using headers. Cheers Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.