If session("loggedIn") = True
Then
strFilePath =
"D:\webfiles\downloads" &
request.querystring("filename")
Set objFSO =
Server.CreateObject("Scripting.FileSystemObject")
If
objFSO.FileExists(strFilePath) Then
Set
objFile =
objFSO.GetFile(strFilePath)
intFileSize =
objFile.Size
Set objFile =
Nothing
strFileName =
request.querystring("filename")
strFileName
= replace(request.querystring("filename"),"
","-")
Response.AddHeader
"Content-Disposition","attachment; filename=" &
strFileName
Response.ContentType
=
"application/x-msdownload"
Response.AddHeader
"Content-Length",
intFileSize
Set objStream =
Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type
= 1
'adTypeBinary
objStream.LoadFromFile
strFilePath
Do While Not
objStream.EOS And
Response.IsClientConnected
Response.BinaryWrite
objStream.Read(1024)
Response.Flush()
Loop
objStream.Close
Set
objStream =
Nothing
Else
Response.write
"Error finding file."
End if
Set
objFSO = Nothing
End If
Tuesday, December 4, 2007
Classic ASP: "Push" File Downloads from A Directory Outside the Application Root
Classic ASP: "Push" File Downloads from A Directory Outside the Application Root