View Full Version : Force download script?
angst
06-02-2006, 06:06 PM
hello,
I'm trying to find a decent force download script for ASP.
I've been searching google.
but most of the scripts I've found don't seem to work correctly.
any ideas would be great,
thanks in advance for your time!
-Ken
angst
06-02-2006, 06:21 PM
ah, ok, i've got it;)
Function DownloadFile(file)
Dim strAbsFile
Dim strFileExtension
Dim objFSO
Dim objFile
Dim objStream
strAbsFile = Server.MapPath(file)
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strAbsFile) Then
Set objFile = objFSO.GetFile(strAbsFile)
Response.Clear
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("There is no such file.")
End If
Set objFSO = Nothing
End Function
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.