General Discussion Undecided where to post - do it here. |
Reply to Thread New Thread |
![]() |
#1 |
|
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. |
![]() |
![]() |
#2 |
|
You need to change the PHP headers to a different file type.
http://www.ryboe.com/tutorials/php-h...force-download |
![]() |
![]() |
#3 |
|
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. |
![]() |
![]() |
#4 |
|
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. |
![]() |
![]() |
#5 |
|
You need to change the PHP headers to a different file type. Do you have any idea how to implement this in Wordpress? |
![]() |
![]() |
#6 |
|
Do you have any idea how to implement this in Wordpress? http://nspeaks.com/656/force-file-do...ad-of-opening/ |
![]() |
![]() |
#7 |
|
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. I want to force the browser (all browsers) to treat the link as a download only. 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? |
![]() |
![]() |
#8 |
|
|
![]() |
![]() |
#9 |
|
|
![]() |
![]() |
#10 |
|
|
![]() |
![]() |
#11 |
|
|
![]() |
![]() |
#12 |
|
Are you ****ing high or something? 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. |
![]() |
![]() |
#13 |
|
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. |
![]() |
![]() |
#14 |
|
you could hack that behavior in with javascript.. personally i wouldnt bother. Actually, here is the site: http://theprestigiousone.com/music/ |
![]() |
![]() |
#15 |
|
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... |
![]() |
![]() |
#17 |
|
good job with that site. impressive |
![]() |
Reply to Thread New Thread |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|