PDA

View Full Version : .mp3 download link/image



rickfink
Jun 22nd, 2009, 08:41 PM
Hey guys,

i have an image that links to a .mp3 file that people can download, but instead of going to the download box, it opens up quicktime and starts playing it. is there a code to make it not play with quicktime? this is firefox btw, haven't tried ie.

sphinx1994
Jun 22nd, 2009, 08:47 PM
I'm not expert here... but this has to do with MIME types. The approach I see taken most often is the one that says "right click this link, and select 'save as' to download". The reason is because the browser typically understands the association of the file being linked and some application on your computer. It IS ( I believe ) possible to force a different kind of download stream... not my area of expertise.

Apostropartheid
Jun 22nd, 2009, 08:49 PM
It's done by a HTTP header. If you want to suggest a filename for the user, add the bit in red.


Content-Disposition: attachment; filename=song.mp3

Add this by PHP or a .htaccess file.

rickfink
Jun 23rd, 2009, 12:06 AM
It's done by a HTTP header. If you want to suggest a filename for the user, add the bit in red.


Content-Disposition: attachment; filename=song.mp3

Add this by PHP or a .htaccess file.

so I add that whole thing into the .htaccess file: Content-Disposition: attachment; filename=song.mp3

Or do I have to add each file name. There's about 50 different .mp3's.

Heres the site:

www.baysidesuperior.org/Bayside/media

Apostropartheid
Jun 23rd, 2009, 12:28 AM
Assuming you're on an Apache webserver, open the .htaccess file. Inside it, copy & paste:


<FilesMatch "\.mp3$">
<IfModule mod_headers.c>
Header set Content-Disposition "attachment"
</IfModule>
</FilesMatch>

Hopefully, that should work.

rickfink
Jun 23rd, 2009, 12:50 AM
Awesome thanks!

rickfink
Jun 25th, 2009, 09:44 PM
Assuming you're on an Apache webserver, open the .htaccess file. Inside it, copy & paste:


<FilesMatch "\.mp3$">
<IfModule mod_headers.c>
Header set Content-Disposition "attachment"
</IfModule>
</FilesMatch>

Hopefully, that should work.

Ok I thought that worked but I tried it on a few other computers using firefox and ie and they both just starting streaming it. Any thoughts?

rickfink
Jun 25th, 2009, 11:05 PM
I looked a few places and I found one site doing this:

http://SITE.org/download.php?file=01_cca09-06-211.mp3

So correct me if I'm wrong..the links the image to the file "download.php" then in the .php there is code that links 01_cca09-06-211.mp3 to the real name of the .mp3?

If that's right, what would the php code be?

Apostropartheid
Jun 25th, 2009, 11:22 PM
Okay, create a file named download.php. Inside it, paste:

<?php
$file = $_GET['file'];
if(file_exists($file . ".mp3")) {
header("Content-Type: audio/mpeg");
header("Content-Disposition: attachment; filename=$file.mp3");
include($file . ".mp3");
}
else {
header("Content-Type: text/html; charset=utf-8");
?>
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Error: File doesn&rsquo;t exist!</title>
<style type="text/css">
html {
font: .8125em/1.8 'lucida grande', 'lucida sans unicode', sans-serif;
}
body {
padding: .75em 1.5em;
margin: 0;
background: #fff;
color: #222;
}
p {
margin: .75em 0;
}
a {
color: #39f;
text-decoration: none;
}
a:hover {
color: #06c;
}
</style>
</head>
<body>
<p><strong>An error has occured</strong>. This file doesn&rsquo;t exist on this server. If you followed a legitimate link, please help us out and <a href="/contact">contact us</a>, so we can both fix this and redirect you to the file you wanted. Thank you.</p>
<p>&laquo; <a href="<?php echo $_SERVER['HTTP_REFERER']; ?>">Go back</a></p>
</body>
</html>
<?php
}
?>
Now, link to your files as http://example.com/download.php?file=filename, replacing example.com and filename as appropriate (do not put .mp3 on the end.) This should do you.

rickfink
Jun 27th, 2009, 05:40 PM
Ok I put the download.php in the folder with all my mp3's, then linked to http://baysidesuperior.org/Sermons/download.php?file=FILENAME but it downloads this really weird file that says this when I open it with notpad:

<br />
<b>Warning</b>: Unexpected character in input: '' (ASCII=30) state=1 in <b>/home4/baysides/public_html/Sermons/06.21.09 - One Body, Many Parts.mp3</b> on line <b>294</b><br />
<br />
<b>Parse error</b>: syntax error, unexpected T_STRING in <b>/home4/baysides/public_html/Sermons/06.21.09 - One Body, Many Parts.mp3</b> on line <b>294</b><br />

rickfink
Jun 30th, 2009, 11:20 PM
Any suggestions? :confused: