If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

[RESOLVED] Force download of MP3 file instead of streaming

Hi, i had encountered problem with MP3 file links:
in IE/Safari/Chrome, when a link to a MP3 file is clicked, the download starts correctly; but in Firefox that doesn't happen - clicking the MP3 file link, it starts an unwanted streaming through a preinstalled FF media plugin.
I need to force MP3 file download in all browsers, is there a simple way to do that in Javascript?

Not really in javascript, but if you set the files mimetype to application/octet-stream you would normally receive the dialog(since that's a universal binary/cannot display in the browser but not saying what file type it is yet mime)

If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
The same applies to HTML and the forums [HTML][/HTML] tags.

MIME types

Originally Posted by scragar

Not really in javascript, but if you set the files mimetype to application/octet-stream you would normally receive the dialog(since that's a universal binary/cannot display in the browser but not saying what file type it is yet mime)

I'm using HTML/VBscript/Javascript (not PHP) in my webpages, but i thought to open a Multimedia Thread because the problem is an unwanted streaming process.
So, how is it possible to change a MIME attribute of an MP3 file?... The need is to leave the file with his original extension because the same file is managed by a web-mediaplayer, but i'd like to let a download by clicking a specified button.

php solution

Thanks EyeForVideo, it seems PHP is the only way to resolve the problem... Unfortunately my pages are ASP extensions and dialog with my Database through VBscript code, so PHP is a little uncomfortable; that's the reason why i hope in a kind of Javascript solution
I've to learn PHP and create a dynamic page which redirects to MP3 files (download.php?fileID=1)... At the moment, i have to admit it, have really no idea in how to build dynamic php code.

Are you sure that it has to be that complex?
You might want to at least give it a try.
Just create a simple PHP file from the code above. Name it
direct_download.php
It is NOT a part of any Web page, it is a small separate file, it just needs to reside in the same folder as the mp3.
The <a> just needs to use that file as the href.
It's just a plain anchor... nothing special, no different than linking to any other web page or file.
Best of luck,
Eye for Video

Dynamic php

@EyeForVideo - Sure, i'll give a try next days... the other thing to consider, is that there's not a single file, but i have to manage a lot of MP3 through a Database, so i have to make the php-content dynamic: the php page has to request an ID number, corresponding to a MP3 file in the DB... i'll study some php to do that (i think is a little different from asp/vbscript code).

the PHP part is just one simple file and can handle multiple files... here's an example:http://www.worldbarefootcenter.com/v...oad_video.html
Download links for a gazzillion video.
It's just an anchor... if you can create a dynamic anchor (forget about there being a link to the PHP file).. link to it just as if it where an image file.
Best wishes,
EfV

Resolved!

Originally Posted by Eye for Video

the PHP part is just one simple file and can handle multiple files...

WONDERFUL, PHP mini-page works pefect!... I'm sorry, i didn't immediately understood that it meant to be a dynamic page, i thought "file" was only an example in php...
I only have to put it in any folder where MP3 files are placed (the files are album-ordered), but really this is not a problem because the php code is very short.

Well, finally i have to admit that PHP code has so many rich functions and i don't understand why other server-side languages (like ASP) cannot do the same things...

Are you saying that the download links I posted do not work in Safari?
The links all work just fine in Safari on my machine.
Or are you having problems when you implement that download php file?

Code:

<a href="direct_download.php?file=fineline.mp3">Download the mp3</a>

of course the href=" has to be the correct path. So if the web page with the link on it is one level up or down, the path has to reflect that.... but it will work just fine.
Also the file= name has to be changed to the name of the file you are downloading. If you put file=direct_download.php, then it will download that file. So recheck your link code.
EfV