LOGO
General Discussion Undecided where to post - do it here.

Reply to Thread New Thread
Old 05-07-2011, 09:19 PM   #1
ENGINESSQ

Join Date
Oct 2005
Posts
419
Senior Member
Default Web devs/hobbyists: quick question.
How can I force an MP3 to download from a click on a webpage?

Right now, when the user clicks a link to an MP3 (depending on the browser plug-ins installed, blah blah) the browser will open an embedded MP3 player. I want to force the browser (all browsers) to treat the link as a download only.

The best solution that I can think of to this is something like this link, but it looks like that does not work in all browsers.

Right now, I have the file zipped since .zip extensions tend to force the download prompt but this is an unnecessary step IMO.

My webpages are PHP, so a PHP solution is ideal, especially if it is elegant.

I also do not want to do that "right-click -> Save As..." nonsense either. I really want to somehow link to a page that sets the HTTP content then directs a download to the browser, something like that.

Any ideas? Thanks.

Edit: If you read Matt Farina's post on the link I provided... something like that is desired.
ENGINESSQ is offline


Old 05-07-2011, 09:37 PM   #2
Pheboasmabs

Join Date
Oct 2005
Posts
448
Senior Member
Default
You need to change the PHP headers to a different file type.

http://www.ryboe.com/tutorials/php-h...force-download
Pheboasmabs is offline


Old 05-07-2011, 09:43 PM   #3
Poeetiol

Join Date
Oct 2005
Posts
352
Senior Member
Default
This is tough, because what you're requesting is actually performed by the browser on the client side. You can write a back-end script and change the header to recognize it as a download file, but even then you still really can't force the client's browser to always obey. If they choose to not always "download" it (or they use something like IE which does whatever it wants), there's really not much you can do.

It's similar with Javascript, you can't really force the client side to use it.
Poeetiol is offline


Old 05-07-2011, 09:52 PM   #4
Pheboasmabs

Join Date
Oct 2005
Posts
448
Senior Member
Default
This is tough, because what you're requesting is actually performed by the browser on the client side. You can write a back-end script and change the header to recognize it as a download file, but even then you still really can't force the client's browser to always obey. If they choose to not always "download" it (or they use something like IE which does whatever it wants), there's really not much you can do.

It's similar with Javascript, you can't really force the client side to use it.
Good points. I took his question literally (how to treat a link as download only) without considering any of the consequences of default applications being set etc etc etc.
Pheboasmabs is offline


Old 05-07-2011, 10:27 PM   #5
ENGINESSQ

Join Date
Oct 2005
Posts
419
Senior Member
Default
You need to change the PHP headers to a different file type.

http://www.ryboe.com/tutorials/php-h...force-download
Ok, as far as structure goes, the site is using WordPress.

Do you have any idea how to implement this in Wordpress?
ENGINESSQ is offline


Old 05-07-2011, 10:30 PM   #6
Pheboasmabs

Join Date
Oct 2005
Posts
448
Senior Member
Default
Do you have any idea how to implement this in Wordpress?
No, but Google does...

http://nspeaks.com/656/force-file-do...ad-of-opening/
Pheboasmabs is offline


Old 05-07-2011, 10:30 PM   #7
ENGINESSQ

Join Date
Oct 2005
Posts
419
Senior Member
Default
Good points. I took his question literally (how to treat a link as download only) without considering any of the consequences of default applications being set etc etc etc.
You planck. That is the very issue that I want to address.
I want to force the browser (all browsers) to treat the link as a download only.
That "all browsers" part was because IE is a PoS that uses the file extension instead of the content type.

Silver Fox,

I suppose that "best effort" is what I am looking for here. Is there anything that can be done beyond what was already stated?
ENGINESSQ is offline


Old 05-07-2011, 10:34 PM   #8
Pheboasmabs

Join Date
Oct 2005
Posts
448
Senior Member
Default
You planck. That is the very issue that I want to address.
I know you mustachioed w**k box. That is what I gave you the link to, but then I remembered (as it was pointed out) that even if you force a download the browser can then apply different behaviour to it.
Pheboasmabs is offline


Old 05-07-2011, 10:41 PM   #9
ENGINESSQ

Join Date
Oct 2005
Posts
419
Senior Member
Default
I know you mustachioed w**k box. That is what I gave you the link to, but then I remembered (as it was pointed out) that even if you force a download the browser can then apply different behaviour to it.
Could you please read the original post and get back to me?
ENGINESSQ is offline


Old 05-07-2011, 10:54 PM   #10
Pheboasmabs

Join Date
Oct 2005
Posts
448
Senior Member
Default
Could you please read the original post and get back to me?
Are you ****ing high or something? I've given you the answer. Stop messing about and fix it.
Pheboasmabs is offline


Old 05-07-2011, 11:01 PM   #11
Poeetiol

Join Date
Oct 2005
Posts
352
Senior Member
Default
I'm afraid not. The best you can really hope for is change the header and cross your fingers the client will get a nice direct download. Majority of users should be good, but there will be a few that will not be getting the result you're trying to accomplish.
Poeetiol is offline


Old 05-07-2011, 11:04 PM   #12
ENGINESSQ

Join Date
Oct 2005
Posts
419
Senior Member
Default
Are you ****ing high or something?
Yes.
I'm afraid not. The best you can really hope for is change the header and cross your fingers the client will get a nice direct download. Majority of users should be good, but there will be a few that will not be getting the result you're trying to accomplish.
I am trying to use a Wordpress plugin... Useless.
ENGINESSQ is offline


Old 07-08-2011, 05:21 AM   #13
koebforfrn

Join Date
Oct 2005
Posts
478
Senior Member
Default
you could hack that behavior in with javascript.. personally i wouldnt bother.
if you find a good solution that works in IE as well, please post it.

if you want *all* mp3 files to be overridden that way i would edit the .htaccess file

or if you only want selected mp3's to be overridden i would use php..
something like the below (but secured, I just hacked that together)

------- save as "forcedownload.php" --------



--------------------------------------------------------

and link to an MP3 using something like
forcedownload.php?file=media/whatever.mp3

you will want to secure this of course, its just hacked together.
koebforfrn is offline


Old 07-08-2011, 06:49 AM   #14
ENGINESSQ

Join Date
Oct 2005
Posts
419
Senior Member
Default
you could hack that behavior in with javascript.. personally i wouldnt bother.
if you find a good solution that works in IE as well, please post it.

if you want *all* mp3 files to be overridden that way i would edit the .htaccess file

or if you only want selected mp3's to be overridden i would use php..
something like the below (but secured, I just hacked that together)

------- save as "forcedownload.php" --------



--------------------------------------------------------

and link to an MP3 using something like
forcedownload.php?file=media/whatever.mp3

you will want to secure this of course, its just hacked together.
Pretty much what I did. I just went to the backend and injected a PHP file that parses a variable out of the URL then directed an octet stream with had similar content to what you posted. Finally, I changed all of the downloads to include the file name.

Actually, here is the site: http://theprestigiousone.com/music/
ENGINESSQ is offline


Old 07-08-2011, 06:54 AM   #15
koebforfrn

Join Date
Oct 2005
Posts
478
Senior Member
Default
good job with that site. impressive

edit - if you wanted to speed up page load a bit, kill off some of the js files like "forcedownload" that you prolly don't need.

could also combine the others into one big JS file, would save some requests. mentioning as i am slightly obsessed with google pagespeed right now...
koebforfrn is offline


Old 08-07-2011, 07:02 AM   #16
AbraroLib

Join Date
Oct 2005
Posts
402
Senior Member
Default
Do what most people do, write 'To download, right click and select save as' beside the link.
AbraroLib is offline


Old 08-07-2011, 07:06 AM   #17
ENGINESSQ

Join Date
Oct 2005
Posts
419
Senior Member
Default
good job with that site. impressive

edit - if you wanted to speed up page load a bit, kill off some of the js files like "forcedownload" that you prolly don't need.

could also combine the others into one big JS file, would save some requests. mentioning as i am slightly obsessed with google pagespeed right now...
I have nothing to do with the design of the site. I was "contracted" in (by the artist himself, a personal friend of mine) to fix this problem.
ENGINESSQ is offline



Reply to Thread New Thread

« Previous Thread | Next Thread »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

All times are GMT +1. The time now is 07:55 PM.
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 PL2
Design & Developed by Amodity.com
Copyright© Amodity