How to download MP3 and not play

How to download MP3 and not play

am 17.11.2007 04:10:55 von Tullamore

Hello,

I want to create a hyperlink to let users download MP3's when they click.
The default behavior is to play. I know they can right-click and save as,
but I don't want to have to tell them that. I also have a MP3 player already
playing on the page.

One googled solution was to zip the file so when the user clicks the zip
file,
the browser would do a open/save as dialog. This almost works - but
the user has to download the zip and then extract the file. I would also
have
to have a "zip" file for each and every MP3 file. Seems a bit bloated...

I want to be able to download the file on click and bypass the play option
that the browser/user may have installed. I played around with the 'type'
attribute but no luck----



I don't want to do FTP and expose user/passwords, etc.

Anyone do anything similar like this?

Thanks in advance.

Regards,
bruce

Re: How to download MP3 and not play

am 17.11.2007 04:35:47 von Richard

On Sat, 17 Nov 2007 03:10:55 GMT, nospam wrote:

> Hello,
>
> I want to create a hyperlink to let users download MP3's when they click.
> The default behavior is to play. I know they can right-click and save as,
> but I don't want to have to tell them that. I also have a MP3 player already
> playing on the page.
>
> One googled solution was to zip the file so when the user clicks the zip
> file,
> the browser would do a open/save as dialog. This almost works - but
> the user has to download the zip and then extract the file. I would also
> have
> to have a "zip" file for each and every MP3 file. Seems a bit bloated...
>
> I want to be able to download the file on click and bypass the play option
> that the browser/user may have installed. I played around with the 'type'
> attribute but no luck----
>
>
>
> I don't want to do FTP and expose user/passwords, etc.
>
> Anyone do anything similar like this?
>
> Thanks in advance.
>
> Regards,
> bruce

how about simply renaming the file? the reason the autoplay begins is the
file extension association.
you could try name.mpx for example. just advise them to rename the file
once downloaded.
but I've never had a case where an mp3 began to play as soon as it was
downloaded. probably due to the user's settings. not the action itself.

Re: How to download MP3 and not play

am 17.11.2007 04:39:24 von Ed Mullen

nospam wrote:
> Hello,
>
> I want to create a hyperlink to let users download MP3's when they click.
> The default behavior is to play.

The default behavior is something you cannot control, it's a function of
the user's browser/system setup. You can't even know what player
software any particular user has, nor how it is configured.

I know they can right-click and save as,
> but I don't want to have to tell them that.

"Suggest" it to them. They'll learn.

I also have a MP3 player already
> playing on the page.

Yuck. Many people detest landing on a page and having sound start
blaring at the unbidden.

> I want to be able to download the file on click and bypass the play option
> that the browser/user may have installed.

You can't. If it's an mp3 file it is my system that determines what
happens.

Put up a page with links to your files. Give a simple explanation for
novices what the possibilities are depending on how their system is
configured - left-click /may/ start playing, right-click and save.

Why worry about it? If I land on your page I'm going to do what I want
to with the resources there regardless of what you /think/ I should do.

--
Ed Mullen
http://edmullen.net
http://mozilla.edmullen.net
http://abington.edmullen.net
Do cemetery workers prefer the graveyard shift?

Re: How to download MP3 and not play

am 17.11.2007 05:01:14 von cwdjrxyz

On Nov 16, 9:10 pm, "nospam" wrote:
> Hello,
>
> I want to create a hyperlink to let users download MP3's when they click.
> The default behavior is to play. I know they can right-click and save as,
> but I don't want to have to tell them that. I also have a MP3 player already
> playing on the page.
>
> One googled solution was to zip the file so when the user clicks the zip
> file,
> the browser would do a open/save as dialog. This almost works - but
> the user has to download the zip and then extract the file. I would also
> have
> to have a "zip" file for each and every MP3 file. Seems a bit bloated...
>
> I want to be able to download the file on click and bypass the play option
> that the browser/user may have installed. I played around with the 'type'
> attribute but no luck----
>
>
>
> I don't want to do FTP and expose user/passwords, etc.
>
> Anyone do anything similar like this?
>
> Thanks in advance.
>
> Regards,
> bruce

Since mp3 files can be played by many players, you never know how the
client computer is going to respond when it connects to a mp3 file.
The owner of the computer may use any of several players for mp3 and
any of several browsers
may be used. In some cases, the mp3 file will be automatically played
on some player, in other cases the computer may ask you if you want to
download or play using which of several players, and the computer
owner may or may not have set options to always handle a mp3 in a
certain way without asking.

If you want to always force download of the mp3 and let the user
decide what to to after downloading, there is one sure way. Rename
song.mp3 as song.deletemp3 and store this file on the server. The
computer will not know this extension, and will ask what you want to
do with the file. You just select a directory to download it to. After
the mp3 is downloaded, you only need to rename the file from some
song.deletemp3 to song.mp3. In other words, you delete "delete" from
the extension. This trick will work for all other types of files I
have tested to force downloading.

On my computer, a mp3 file can be played on several players, including
WMP 11, Real 11 beta, QT, Winamp, etc. I may be using Firefox, Opera,
IE6, Seamonkey, Safari for Windows on the Windows XP OS. The way I
have my computer set up, certain combinations of browsers and players
start playing a mp3 automatically, others ask you what player you wish
to use, and still others offer download only.

Re: How to download MP3 and not play

am 17.11.2007 06:16:08 von Shion

nospam wrote:
> Hello,
>
> I want to create a hyperlink to let users download MP3's when they click.
> The default behavior is to play. I know they can right-click and save as,
> but I don't want to have to tell them that. I also have a MP3 player already
> playing on the page.

You can do this without a bit of "hacking", and there are better and worse
ways to do this.

1. You can use a script that sends the file in question, first it sends a
false header that tells that the file isn't a mp3, this has the advantage of
that the file don't have to be renamed.

2. Archive the file with gzip, as a browser that knows a bit about standard
(of course the user settings applies here too) would unarchive the file.

3. Change the file extension.

4. Modify the servers mime types (has the disadvantage that all mp3 would
become downloadable only)


> I don't want to do FTP and expose user/passwords, etc.

Switching protocol won't change how a browser will behave.

--

//Aho

Re: How to download MP3 and not play

am 17.11.2007 18:58:19 von Tullamore

"J.O. Aho" wrote in message
news:5q7bopFum4trU1@mid.individual.net...
> nospam wrote:
>> Hello,
>>
>> I want to create a hyperlink to let users download MP3's when they click.
>> The default behavior is to play. I know they can right-click and save
>> as,
>> but I don't want to have to tell them that. I also have a MP3 player
>> already
>> playing on the page.
>
> You can do this without a bit of "hacking", and there are better and worse
> ways to do this.
>
> 1. You can use a script that sends the file in question, first it sends a
> false header that tells that the file isn't a mp3, this has the advantage
> of
> that the file don't have to be renamed.
>
> 2. Archive the file with gzip, as a browser that knows a bit about
> standard
> (of course the user settings applies here too) would unarchive the file.
>
> 3. Change the file extension.
>
> 4. Modify the servers mime types (has the disadvantage that all mp3 would
> become downloadable only)
>
>
>> I don't want to do FTP and expose user/passwords, etc.
>
> Switching protocol won't change how a browser will behave.
>
> --
>
> //Aho

Thanks for all of the replies. I am interested in using the script
as Aho mentioned. Duh, I sort of understand what you are saying,
but need to clarify.

This would be a server side script - like cgi?
or client side - like javascript?

Thanks,
bruce

Re: How to download MP3 and not play

am 17.11.2007 19:40:11 von Toby A Inkster

nospam wrote:

> I want to create a hyperlink to let users download MP3's when they click.
> The default behavior is to play. I know they can right-click and save as,
> but I don't want to have to tell them that.

The proper way is to send an HTTP header saying:

Content-Disposition: attachment

This tells the browser that you *intend* for the file to be saved rather
than handled using a plugin. The browser may be configured to ignore this
preference -- and so it should be: it's really the visitor's choice what
they do with the file once it arrives on their system -- but at least you
have made your intentions known.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 11 days, 1:36.]
[Now Playing: ./bjork_-_state_of_emergency.ogg.]

Belgium
http://tobyinkster.co.uk/blog/2007/11/17/belgium/

Re: How to download MP3 and not play

am 17.11.2007 19:47:15 von Harlan Messinger

nospam wrote:
> Hello,
>
> I want to create a hyperlink to let users download MP3's when they click.
> The default behavior is to play.

The default behavior is whatever the user's browser is configured for it
to be, and he wants to listen to MP3s directly without downloading them
first, that isn't your business.

> I know they can right-click and save as,
> but I don't want to have to tell them that.

Why should your site behave differently for them from every other site?
Do you see yourself as a Web savior protecting people from the horrible
burden of right-clicking?

> I also have a MP3 player already
> playing on the page.

Then you're the one who has created the problem.

> One googled solution was to zip the file so when the user clicks the zip
> file,
> the browser would do a open/save as dialog. This almost works - but
> the user has to download the zip and then extract the file. I would also
> have
> to have a "zip" file for each and every MP3 file. Seems a bit bloated...

The least bloated approach is to stop second-guessing what the user
wants to do.

Re: How to download MP3 and not play

am 17.11.2007 20:26:50 von Shion

nospam wrote:

> Thanks for all of the replies. I am interested in using the script
> as Aho mentioned. Duh, I sort of understand what you are saying,
> but need to clarify.
>
> This would be a server side script - like cgi?
> or client side - like javascript?

It has to be server side like php or any other scripting language.

$file="themp3file.mp3";
header('Content-type: application/octet-stream');
header('Content-Length: '. filesize($file));
header("Content-Disposition: attachment; filename='{$file}'");
readfile($file);
?>

For more info, you can check the header() function on the PHP online manual
http://www.php.net/manual/en/function.header.php

--

//Aho

Re: How to download MP3 and not play

am 18.11.2007 02:35:17 von Tullamore

"J.O. Aho" wrote in message
news:5q8tjrFusdcmU1@mid.individual.net...
> nospam wrote:
>
>> Thanks for all of the replies. I am interested in using the script
>> as Aho mentioned. Duh, I sort of understand what you are saying,
>> but need to clarify.
>>
>> This would be a server side script - like cgi?
>> or client side - like javascript?
>
> It has to be server side like php or any other scripting language.
>
> > $file="themp3file.mp3";
> header('Content-type: application/octet-stream');
> header('Content-Length: '. filesize($file));
> header("Content-Disposition: attachment; filename='{$file}'");
> readfile($file);
> ?>
>
> For more info, you can check the header() function on the PHP online
> manual
> http://www.php.net/manual/en/function.header.php
>
> --
>
> //Aho

Aho,
Thanks for you help. All this trouble to give my music away for free!!!

Regards,
bruce

Re: How to download MP3 and not play

am 18.11.2007 03:43:03 von nigel_moss

While the city slept, Ed Mullen (ed@edmullen.net) feverishly typed...

> nospam wrote:
[...]
>> I also have a MP3 player already
>> playing on the page.
>
> Yuck. Many people detest landing on a page and having sound start
> blaring at the unbidden.

Sadly, Myspace is making such a situation more common... :-(

Cheers,
Nige

--
Nigel Moss http://www.nigenet.org.uk
Mail address will bounce. nigel@DOG.nigenet.org.uk | Take the DOG. out!
"Your mother ate my dog!", "Not all of him!"

Re: How to download MP3 and not play

am 18.11.2007 08:40:57 von Bone Ur

Well bust mah britches and call me cheeky, on Sat, 17 Nov 2007 19:26:50
GMT J.O. Aho scribed:

>> This would be a server side script - like cgi?
>> or client side - like javascript?
>
> It has to be server side like php or any other scripting language.
>
> > $file="themp3file.mp3";
> header('Content-type: application/octet-stream');
> header('Content-Length: '. filesize($file));
> header("Content-Disposition: attachment; filename='{$file}'");
> readfile($file);
> ?>

The above code you posted was unfamiliar to me and looked interesting so I
tried it out using a .gif file instead of an .mp3, and voila!, it worked
except that I had to delete the single quotes from the Disposition line (-
and, following, deleted the then-superfluous curly braces) to avoid
receiving them in the open/save-to file name. Does this not happen to you
or am I missing something. Anyway, very clever.

--
Bone Ur (aka Neredbojias)
Cavemen have formidable pheromones.

Re: How to download MP3 and not play

am 18.11.2007 10:15:21 von jkorpela

Scripsit nospam:

> All this trouble to give my music away for free!!!

_Your_ music? Well, maybe. Surely "nospam" is not your name, so I wouldn't
be so sure about other statements of yours either.

But you insist on making things more difficult when you require "download
and not play". If you just used a nice, cool _link_ that lets the _user_
decide, you would get better page quality with less effort. But wannabe
authors seem to hate such ideas.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Re: How to download MP3 and not play

am 18.11.2007 12:48:30 von tabkanDELETETHISnaz

nospam wrote:


> I want to create a hyperlink to let users download MP3's when they click.
> The default behavior is to play.

Wrong. The default behavior depends on the user agent.
With the browser I currently use (Opera) on Windows, the default behavior
is to show a dialog box giving the choice between saving or opening with
the default MP3 player and there's a [remember my choice] checkbox.
With Firefox, the default behavior is the same on my computer.
With Internet Explorer 6, the default behavior is the same, but the
current behavior on my computer is to download the file with my custom
download manager but without opening it.

I don't want that you override this behavior. If I wished that MP3 files
be saved without confirmation, I would configure my browser to do so. I
can easily specify the default action for every MIME type in my browser
settings.

Why do you think that you know better what I want to do than I?
Or maybe, you think that YOU would like files to be saved by default but
you don't know how to configure your browser and think that you would
offer the user a service by giving them the "better behavior"?
But, the fact is that it isn't a better behavior. It is a different
behavior. Please, let the user have his own preferences.

--
If you've a question that doesn't belong to Usenet, contact me at