[ASP] Bestand laten downloaden met Save as (a la CNET))

Pagina: 1
Acties:
  • 47 views sinds 30-01-2008

  • DirtyHennessy
  • Registratie: Oktober 2001
  • Laatst online: 31-07 19:51
Ik wil een bestand laten downloaden zonder dat IE het zelf afspeelt!

dit is de HTML:
<HTML>
<HEAD>
<TITLE>Download mp3'z</TITLE>
</HEAD>
<BODY>
<a href="download.asp?file=1.mp3" Target="_blank">Download</a>
</BODY>
</HTML>


Dit is mijn ASP pagina:

<%@Language="VBScript"%>
<%Response.Buffer = True%>
<%
On Error Resume Next
Dim strPath
strPath = CStr(Request.QueryString("file"))
'-- do some basic error checking for the QueryString
If strPath = "" Then
Response.Clear
Response.Write("No file specified.")
Response.End
ElseIf InStr(strPath, "..") > 0 Then
Response.Clear
Response.Write("Illegal folder location.")
Response.End
ElseIf Len(strPath) > 1024 Then
Response.Clear
Response.Write("Folder path too long.")
Response.End
Else
Call DownloadFile(strPath)
End If

Private Sub DownloadFile(file)
'--declare variables
Dim strAbsFile
Dim strFileExtension
Dim objFSO
Dim objFile
Dim objStream
'-- set absolute file location
strAbsFile = Server.MapPath(file)
'-- create FSO object to check if file exists and get properties
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'-- check to see if the file exists
If objFSO.FileExists(strAbsFile) Then
Set objFile = objFSO.GetFile(strAbsFile)
'-- first clear the response, and then set the appropriate headers
Response.Clear
'-- the filename you give it will be the one that is shown
' to the users by default when they save
Response.AddHeader "Content-Disposition", "attachment; filename=" & objFile.Name
Response.AddHeader "Content-Length", objFile.Size
Response.ContentType = "application/octet-stream"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
'-- set as binary
objStream.Type = 1
Response.CharSet = "UTF-8"
'-- load into the stream the file
objStream.LoadFromFile(strAbsFile)
'-- send the stream in the response
Response.BinaryWrite(objStream.Read)
objStream.Close
Set objStream = Nothing
Set objFile = Nothing
Else objFSO.FileExists(strAbsFile)
Response.Clear
Response.Write("No such file exists.")
End If
Set objFSO = Nothing
End Sub
%>

hoe los ik dit op??!?

  • whoami
  • Registratie: December 2000
  • Nu online
Sorry, maar GoT (en P&W) is geen 'doe-eens-ff-dit-voor-mij'-service.

Je zult zelf wat onderzoek moeten doen en initiatief tonen. Gewoon uw code die je hebt hier posten en zeggen wat je wilt is niet toegelaten.
Bezoekers gaan hier niet jouw probleem volledig voorkauwen, en jij moet niet verwachten dat er hier iemand gratis jouw probleem zomaar gaat oplossen.

Lees misschien even de Quickstart en de P&W FAQ.

Welkom in P&W (FAQ-13/7/2002)
Welkom in P&W -> Quickstart om snel aan de slag te kunnen

https://fgheysels.github.io/


Dit topic is gesloten.