Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1529
  • Last Modified:

Force download when clicked (Save Target As...)

I would like to know of a script that forces a .mp3 or .wma, .rm file to download no matter what the users has set as a default for this file.  Same as if the user was to select the right click option:
"Save Target As..."

Example,
http://www.hydrozeen.com/Hydrozeen-Pile%20of%20Bones.mp3

Normally when you click on the basic link your computer settings will either stream this into your system or ask to download it.

Now you can always right click and then select:
Save Target As...
and this is what I would like the default for the link to be, so how do I change a basic .mp3 link into a force download link?

Thanks for the answer,
Stephen

0
lnternet
Asked:
lnternet
  • 3
1 Solution
 
justinbilligCommented:
heres an example but it's ASP

http://www.psacake.com/web/if.asp
0
 
justinbilligCommented:
when the user clicks the link you could submit a download form to a new window then use that script on that page
0
 
Ayesha_KCommented:
Hi,

I'm using the following function in ASP.NET to force the IE to download my file and not start opening it in its specified format.

    Sub DownloadFile(ByVal sender As Object, ByVal e As EventArgs)
        On Error GoTo errHandler
        Dim strPhysicalPath As String
        Dim objFileInfo As System.IO.FileInfo
        Dim ErrMsg As String

        strPhysicalPath = Server.MapPath(Session("MyFileName"))

        'exit if file does not exist
        If Not System.IO.File.Exists(strPhysicalPath) Then Exit Sub
        objFileInfo = New System.IO.FileInfo(strPhysicalPath)
        Response.Clear()

        Response.ClearHeaders()
        Response.Clear()
        Response.ContentType = "text/plain"
        Response.Charset = ""
        Response.AddHeader("Content-Disposition", "attachment;filename=" + objFileInfo.Name)
        Response.AddHeader("Content-Length", objFileInfo.Length.ToString())
        Response.WriteFile(strPhysicalPath)
        Response.Flush()
        Response.Close()
        Exit Sub

errHandler:
        ErrMsg = Err.Description
    End Sub
0
 
justinbilligCommented:
I think the points should be split between myself and Ayesha_K since both are viable options
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now