Force File Download Box

Discussion in 'Javascript' started by BOHICA, Jan 10, 2004.

  1. BOHICA

    BOHICA Guest

    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?
     
    BOHICA, Jan 10, 2004
    #1
    1. Advertising

  2. 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
     
    Thomas 'PointedEars' Lahn, Feb 12, 2004
    #2
    1. Advertising

  3. 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
     
    Thomas 'PointedEars' Lahn, Feb 13, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Cox [Microsoft MVP]

    Re: Force File Download XML Problem

    Ken Cox [Microsoft MVP], Jul 19, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    703
  2. Albano Alves

    Force File to Download

    Albano Alves, Feb 15, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    385
    Mark Rae
    Feb 15, 2005
  3. Kele
    Replies:
    0
    Views:
    2,799
  4. Frank
    Replies:
    11
    Views:
    2,980
    A Hess
    Dec 12, 2003
  5. Gnarlodious
    Replies:
    4
    Views:
    17,605
    elizas
    May 5, 2010
Loading...

Share This Page