Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Special Interests > Visual Media > Web Design and Development

Reply
 
Thread Tools Search this Thread Display Modes
Old Sep 18, 2008, 08:43 AM   #1
Mr Skills
macrumors 6502a
 
Mr Skills's Avatar
 
Join Date: Nov 2005
Force a link to download an MP3 rather than play it?

I have put some free MP3s on my band's website (link in the sig) and hosted them on idisk, but when I click on them they play rather than downloading. It feels inelegant to zip them or ask people to right-click.

All the searches I have done on this topic suggest that it's just tough luck BUT.... if I host the MP3s on garageband.com they download, so they have obviously found some way round it.

website download link

garageband.com download link

The only obvious difference is that on garageband the song has "?|pe1|S8LTM0LdsaSgYFi3Y2k" after the filename on the link. Also, I've seen talk of changing MIME types so the browser doesn't know it's an MP3. Is this what I should do, and if so, how?

Thanks!
__________________
Download free songs
Mr Skills is offline   0 Reply With Quote
Old Sep 18, 2008, 09:06 AM   #2
mshepherd
macrumors regular
 
Join Date: Mar 2004
You have to change the content type in the header to force download. This will take some server side scripting. This is how i would do it in PHP, the application part of the content type forces it to be downloaded.

Code:
<?php
// We'll be outputting a MP3
header('Content-type: application/mp3');
// It will be called file.mp3
header('Content-Disposition: attachment; filename=file.mp3');
header('Content-Length: '.filesize("somefile.mp3"));
// The MP3 source is in somefile.pdf
//readfile("somefile.mp3");
readfile_chunked("somefilename.pdf");

function readfile_chunked($filename){ 
 $chunksize = 1*(1024*1024); // how many bytes per chunk 
 $buffer = ''; 
 $handle = fopen($filename, 'rb'); 
 if ($handle === false) { 
 return false; 
 } 
 while (!feof($handle)) { 
   $buffer = fread($handle, $chunksize); 
 print $buffer; 
 } 
 return fclose($handle); 
 } 
?>
mshepherd is offline   0 Reply With Quote
Old Sep 18, 2008, 10:19 AM   #3
Mr Skills
Thread Starter
macrumors 6502a
 
Mr Skills's Avatar
 
Join Date: Nov 2005
Thanks msheperd - the only problem (apart from my minimal paint-by-numbers HTML ability!) is that the website is actually a Blogger page, and the links are just HTML within a blog post... so I don't think I've got any server-side access.

Is it possible to put such headers/php within an HTML widget?
__________________
Download free songs
Mr Skills is offline   0 Reply With Quote
Old Sep 18, 2008, 12:15 PM   #4
mshepherd
macrumors regular
 
Join Date: Mar 2004
the only thing you may be able to do is change the mime types within the apache config if you have access to that.
mshepherd is offline   0 Reply With Quote
Old Sep 18, 2008, 12:25 PM   #5
Wee Beastie
macrumors regular
 
Join Date: Aug 2007
Location: In the snow with Rosebud
In this case, since you say you don't have too much html/scripting experience, it might be best to just give your users instructions.

"Right click the links below and select 'Save Target As' to download to your hard drive" or something like that.

This will give them a choice--some people might rather stream it. Or this could be an opportunity to delve even deeper into the wonderful world o' web development. Good luck.
__________________
iMac 2.8 24"
MBP 2.4 i5 15" AG
Wee Beastie is offline   0 Reply With Quote
Old Sep 18, 2008, 12:56 PM   #6
rickiac
macrumors newbie
 
Join Date: Dec 2007
Force a link to download an MP3 rather than play it?

Use FTP intead of HTTP as the source link, this should bring up the save / open dialog box.
rickiac is offline   0 Reply With Quote
Old Sep 18, 2008, 04:55 PM   #7
Mr Skills
Thread Starter
macrumors 6502a
 
Mr Skills's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by mshepherd View Post
the only thing you may be able to do is change the mime types within the apache config if you have access to that.
It's a blogger blog, which just lets you put HTML into a box. So I don't think I've got access to things like Apache config (which I assume would be on the server).

Quote:
Originally Posted by Wee Beastie View Post
In this case, since you say you don't have too much html/scripting experience, it might be best to just give your users instructions.

"Right click the links below and select 'Save Target As' to download to your hard drive" or something like that.

This will give them a choice--some people might rather stream it. Or this could be an opportunity to delve even deeper into the wonderful world o' web development. Good luck.
Well I know a little HTML... enough to follow instructions. It's just that it has to be relatively simple HTML/Javascript because it's going in a blogger widget. I've already got the "save as" instruction on there, but it's just so inelegant, especially since it's a slightly different instruction on every browser! (Which reminds me... bizarrely, sometimes you right-click on a song in Safari, the menu says "download linked file" and sometimes it says "save as" but it changes when I reload the page...)

Quote:
Originally Posted by rickiac View Post
Use FTP intead of HTTP as the source link, this should bring up the save / open dialog box.
Good suggestion... but it didn't work. The browser was just endlessly loading (maybe because iDisk is webdav and not FTP?).

Thanks for all the suggestions so far... keep them coming!
__________________
Download free songs
Mr Skills is offline   0 Reply With Quote
Old Sep 18, 2008, 05:39 PM   #8
Wee Beastie
macrumors regular
 
Join Date: Aug 2007
Location: In the snow with Rosebud
Quote:
I've already got the "save as" instruction on there, but it's just so inelegant, especially since it's a slightly different instruction on every browser! (Which reminds me... bizarrely, sometimes you right-click on a song in Safari, the menu says "download linked file" and sometimes it says "save as" but it changes when I reload the page...)
This is true. Frankly I don't know the exact solution to your problem. Maybe if you zipped the mp3 before uploading to your blog. Then the browser won't be able to stream it. They'll have to download it and unzip it themselves (I think). Might work...
__________________
iMac 2.8 24"
MBP 2.4 i5 15" AG
Wee Beastie is offline   0 Reply With Quote

Reply
MacRumors Forums > Special Interests > Visual Media > Web Design and Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
How to download mp3-alarm tone mortenandersen iPhone and iPod touch Apps 0 Nov 26, 2013 12:43 PM
All iPads: does buying the first gen ipad mini force ios 7 download? jaywood iPad 1 Nov 21, 2013 09:01 AM
Why do I get two copies of the same file when I download an mp3??? Starshade Mac Basics and Help 3 Sep 9, 2013 04:26 AM
iOS 7 Download Link DAMNiatx Wasteland 0 Jun 10, 2013 01:59 PM

Forum Jump

All times are GMT -5. The time now is 07:04 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC