Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Download with HTTPS

Status
Not open for further replies.

snwbdr

Programmer
Aug 1, 2003
4
US
I have been working on a file download application which will allow users to download files from our site, it works fine when the site has https turned off, but when I turn it on the page fails to allow me to download. I get a ms ie error. Code below

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-Disposition", "inline;" & 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
call logevent(0,"Done, I think.")

Set objStream = Nothing
Set objFile = Nothing
response.End
Else 'objFSO.FileExists(strAbsFile)
Response.Clear
Response.Write("No such file exists.")
call logevent(0,"No such file exists.")
End If
Set objFSO = Nothing
End Sub

'Call File with File Name
Call DownloadFile(strPath)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top