Force File Download Box

B

BOHICA

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?
 
T

Thomas 'PointedEars' Lahn

OHICA said:
<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
 
T

Thomas 'PointedEars' Lahn

Thomas said:
<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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top