Log in

View Full Version : left click to save as



imSOmusic
07-11-2010, 03:51 PM
hi, my question is about the same as an existing post (http://www.dynamicdrive.com/forums/showthread.php?t=909) but I didn't understand it and I need help for another type of file.

I have a mp3 website (http://imsomusic.com) and when users search of a song, it simply crawls the web to find it from different sources. My download links are currently direct links to the mp3 song found so the users need to right click and "save link target as" to get the song. I would like users to be able to simply left click on the link to download.

I googled and found a php script that may help me but i don't understand how to implement it (I'm new to php) here is the link (http://www.computing.net/webdevel/wwwboard/forum/792.html).

So please help me find a way to download mp3's with a left click, thank you.

djr33
07-11-2010, 04:35 PM
This is complex.
The browser decides what to do with a file. The only way to get the browser to download instead of viewing (since it's basically the same behavior, based on what the browser thinks it should do) is to trick the browser into thinking it's another kind of file.
So you use a different header and the browser thinks it can't play it, etc.

One guaranteed way is to offer your mp3s within zip files. Then the user must download that and extract it, and it saves bandwidth. It's one more step for the user, but that guarantees they can't play it.

Basically you can look for several ways to fake the filetype but it won't be easy or work in all browsers.

azoomer
07-11-2010, 05:05 PM
Hi imSOmusic ! To my big surprise it actually works the script you are linking to.
I made a quick test of it and you can see it HERE. Sorry this link and the files on my server are removed for security reasons
To make it easier for you to implement I have attached a zip folder. You can download and unzip it and see how the files are made. I put a silly picture instad of the mp3 to make it smaller in size to upload. Of course you would have to replace the link url's with your own. I don't know much about php so i can't really explain it, but it seems to work !!

edit; It works in ff as expected. Ie gives the usual download warnings. Chrome downloads the file without having to confirm. Haven't tried safari and opera yet.

edit 2: I don't recommend using script before investigating if it is secure to have on your server. I removed it from my server.

imSOmusic
07-11-2010, 06:07 PM
nice but my sources are from other servers.. (I'm just a music search engine but with direct links to "play" and "download" the songs)

my download links are like that:

<body bgcolor="#FFFFFF">
<div align="center" style="width:100%;">
<?php

$download = $_GET['url'];

?>

<a href="<$download;?>">Download</a>

</div>
</body>

so how can I integrate the download.php ?

azoomer
07-11-2010, 06:22 PM
I guess this script works if the download.php is on the same server as the file that should be downloaded. Can't see how it should work on a remote server, but what do I know ?

traq
07-11-2010, 06:24 PM
two problems:

1) the browser (them), not the server (you) decides whether to download something or open it by default.

2) since the songs aren't yours, you have no control over how they are presented to the browser.

Sorry to say it, but you're basically "out of luck" - twice.

imSOmusic
07-11-2010, 06:36 PM
thanks anyway guys! you where very useful (if it had worked)

I'll simply keep telling my visitors to right click and save .. :(

traq
07-11-2010, 06:56 PM
depending on how complex you want to make things (and copyright issues, of course), you could develop a script that downloads the selected file to your server when clicked, (optionally) zips it, and then offers it to the user for download. This would also take longer - there would be a noticeable pause - but you could also cache the file, so popular songs wouldn't have to be downloaded repeatedly. But I suspect this is beyond what you want to do, and, as I mentioned, it could spiral into a terrible copyright mess.