By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,504 Members | 1,143 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,504 IT Pros & Developers. It's quick & easy.

Force File Download Box

P: n/a
I would like on my page when users click one of my mp3 files for the
dialog box to pop up so they can choose to save the file to disk
instead of trying to open through IE, but the dang thing won't do it.
Is there script I can plug in without having to do asp or pl files?
(Cobalt server does not allow these files)

here is an example

<a href="/muzak/wong.mp3"> as link

what can I do to this in javascript to make it behave?
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <db*************************@posting.google.com> ,
ro*******@hotmail.com (BOHICA) writes:
I would like on my page when users click one of my mp3 files for the
dialog box to pop up so they can choose to save the file to disk
instead of trying to open through IE, but the dang thing won't do it.
Is there script I can plug in without having to do asp or pl files?
(Cobalt server does not allow these files)


<confused look on face>
I have IE set up to play music within IE and you are wanting to write some
javascript that will change the way I chose to have my browser setup and
thereby confuse the crap outta me?
</confused look>

Make the link point to a zip file instead........

--
Randy
Jul 20 '05 #2

P: n/a
OHICA wrote:
<a href="/muzak/wong.mp3"> as link

what can I do to this in javascript to make it behave?


Nothing if you are talking about *client-side* J(ava)Script. JS is but
a language, a tool. It can use core objects, host objects and user
objects. Unfortunately, there is no object that does what you are
looking for _and_ is available in all user agents.

So to be sure, you need to reference a server-side script (I recommend
PHP instead of JS) that takes the filename as parameter and serves the
respective file with a different MIME content type.

<OT>

Content-Type: application/octet-stream usually triggers a file download,
the correct Content-Type (audio/mpeg) will trigger either a file
download or the configured plugin to download (and play) it (which is
what you have experienced, others may have not!). I have read about a
better way than app/8-stream but alas I forgot it. (If anyone can tell,
please do so.)

For .mp3 files, a server-side script could return a playlist (.m3u is
common) as well. I do not know for sure, but that could allow for
streamed downloads. (CMIIW)

For example:

[<a href="foobar.mp3">Play</a>]
[<a href="playlist?file=foobar.mp3">Play with playlist</a>]
[<a href="download?file=foobar.mp3">Download</a>]

You need to configure the web server to serve .mp3 files as audio/mpeg.
For NCSA-httpd compatibles using httpd.conf or .htaccess, like the
Apache HTTP Server:

AddType audio/mpeg .mp3

Untested download.php:

<?php

if (isset($HTTP_GET_VARS['file']))
{
header('Content-Type: application/octet-stream');
include($HTTP_GET_VARS['file']);
}

?>

</OT>
HTH

PointedEars
Jul 20 '05 #3

P: n/a
Thomas 'PointedEars' Lahn wrote:
<OT>

Content-Type: application/octet-stream usually triggers a file download,
the correct Content-Type (audio/mpeg) will trigger either a file
download or the configured plugin to download (and play) it (which is
what you have experienced, others may have not!). I have read about a
better way than app/8-stream but alas I forgot it. (If anyone can tell,
please do so.)


JFYI, I found it again:

<http://www.php.net/manual/en/function.header.php>

/generate dynamic content
PointedEars
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.