lonewolf32
Programmer
I am trying to do a file download (zip, pdf, any type really). When I click the link, I get a Open/Save/Cancel dialog as expected. If I click Save, it works OK, opening the Save dialog. But if I click Open, I get another identical Open/Save/Cancel dialog! At this point if I click Open again, it works fine! Here is the code, can anybody help?
File 1 (test.asp):
<HTML>
<HEAD>
</HEAD>
<BODY>
<%session("axs4mms" = 1%>
<A HREF="/scripts/dtest.asp?file=file1.zip">File 1</A>
</BODY>
</HTML>
File 2 (dtest.asp):
<%
strFile = replace(replace(Request("file","\","","/",""
' make sure you are on the latest MDAC version for this to work
' -------------------------------------------------------------
' get full path of specified file
strPath = "c:\downloads\"
strFilename = strPath & strFile
' clear the buffer
Response.Buffer = True
Response.Clear
' create stream
Set s = Server.CreateObject("ADODB.Stream"
s.Open
' Set as binary
s.Type = 1
' load in the file
on error resume next
' check the file exists
Set fso = Server.CreateObject("Scripting.FileSystemObject"
if not fso.FileExists(strFilename) then
Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>"
Response.End
end if
' get length of file
Set f = fso.GetFile(strFilename)
s.LoadFromFile(f.name)
if err then
Response.Write("<h1>Error: </h1>" & err.Description & "<p>"
Response.End
end if
' send the headers to the users browser
Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
Response.AddHeader "Content-Length", f.size
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"
' output the file to the browser
Response.BinaryWrite s.Read
Response.Flush
' tidy up
s.Close
Set s = Nothing
%>
File 1 (test.asp):
<HTML>
<HEAD>
</HEAD>
<BODY>
<%session("axs4mms" = 1%>
<A HREF="/scripts/dtest.asp?file=file1.zip">File 1</A>
</BODY>
</HTML>
File 2 (dtest.asp):
<%
strFile = replace(replace(Request("file","\","","/",""
' make sure you are on the latest MDAC version for this to work
' -------------------------------------------------------------
' get full path of specified file
strPath = "c:\downloads\"
strFilename = strPath & strFile
' clear the buffer
Response.Buffer = True
Response.Clear
' create stream
Set s = Server.CreateObject("ADODB.Stream"
s.Open
' Set as binary
s.Type = 1
' load in the file
on error resume next
' check the file exists
Set fso = Server.CreateObject("Scripting.FileSystemObject"
if not fso.FileExists(strFilename) then
Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>"
Response.End
end if
' get length of file
Set f = fso.GetFile(strFilename)
s.LoadFromFile(f.name)
if err then
Response.Write("<h1>Error: </h1>" & err.Description & "<p>"
Response.End
end if
' send the headers to the users browser
Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
Response.AddHeader "Content-Length", f.size
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"
' output the file to the browser
Response.BinaryWrite s.Read
Response.Flush
' tidy up
s.Close
Set s = Nothing
%>