473,387 Members | 1,596 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Force File Download Box

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
3 10111
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: lmb | last post by:
Hi all, Does anyone know how to force the download of a text file ? In my script, I tried : header("location: my_text_file.txt") ; ....and of course, I get my text in my browser as I wanted a...
1
by: Navin | last post by:
hi, guys i am using the following code to force a file download dialog in asp Response.ContentType = "application/vnd.ms-excel" response.AddHeader "content-disposition","attachment; filename="...
1
by: Navin | last post by:
hi, guys i am using the following code to force a file download dialog in asp Response.ContentType = "application/vnd.ms-excel" response.AddHeader "content-disposition","attachment; filename="...
4
by: Robert Oschler | last post by:
Hello, I have a web site that has an audio file on it that I make available for download. Right now I'm using the "right-click/save-as" approach. This is because left-clicking the link to the...
4
by: Kevin Muenzler, WB5RUE | last post by:
How do I force a browser to download a file instead of displaying it? In other words I have a page with MP3 and WMA files on it and I would like for the visitor to download the file instead of...
0
by: Rhys666 | last post by:
Basically I have a link that opens my download page and the querystring identifies the type of 'template' Excel spreadsheet has asked to download. The download page reads the querystring,...
0
by: karups | last post by:
hi, Can some one help me out? How to Force file download box when clicking on a link for a .pdf file. Normally it opens the pdf in IE itself, instead it should ask for (open , save and...
1
by: JP SIngh | last post by:
Hi All We have a page which we want to allow our users to download files. Can someone point to peice of code that we can use to force the download as opposed to opening the files in the...
6
by: ziycon | last post by:
I'm wondering if its possible to force a file to be downloaded when you go to a certain page. Say if you click on the link for the page and then it will go to that page and give you the prompt box to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.