olduhu
10-01-2002, 01:54 PM
I needed a script to force downloads of files like *.doc, *.jpeg, etc... instead of opening them automatically in the browser window. Well, I have found a script that does the job quite well - first you are asked whether to open or save the document and then you can specify where to save the file to.
However, if the user cancels the second dialog box (the Save as... box), the browser hangs up. You then have to close the browser, disconnect and reconnect to make this site work again. The reason for this is that although the user cancelled the file-transfer the connection stays open.
Now my question:
Could anyone please tell me how to avoid this malfunction? I know that I have to somehow check whether the "Cancel"-Button was pressed in the second dialog, or at least I could imagine it to work that way... ;-) But how do I do this?
Here's the script I've used so far:
<%
Response.Buffer = TRUE
Response.Clear
Response.Expires = 0
Response.ContentType = "application/msword"
strFileName = "test.doc"
strMyPath = Server.MapPath("./docs/") & "\" & strFileName
Response.AddHeader "Content-Disposition","attachment;filename=" & strFileName
Set objFileSys = Server.CreateObject("Scripting.Filesystemobject")
Set objFile = objFileSys.GetFile(strMyPath)
FileSize = objFile.Size
Set objFile = Nothing
Set objFile = objFileSys.OpenTextFile(strMyPath, 1, false, -1)
Response.BinaryWrite(objFile.Read(FileSize))
Set objFile = Nothing
Set objFileSys = Nothing
Response.Flush
%>
Thanks for your help!!! I'd really appreciate it...
However, if the user cancels the second dialog box (the Save as... box), the browser hangs up. You then have to close the browser, disconnect and reconnect to make this site work again. The reason for this is that although the user cancelled the file-transfer the connection stays open.
Now my question:
Could anyone please tell me how to avoid this malfunction? I know that I have to somehow check whether the "Cancel"-Button was pressed in the second dialog, or at least I could imagine it to work that way... ;-) But how do I do this?
Here's the script I've used so far:
<%
Response.Buffer = TRUE
Response.Clear
Response.Expires = 0
Response.ContentType = "application/msword"
strFileName = "test.doc"
strMyPath = Server.MapPath("./docs/") & "\" & strFileName
Response.AddHeader "Content-Disposition","attachment;filename=" & strFileName
Set objFileSys = Server.CreateObject("Scripting.Filesystemobject")
Set objFile = objFileSys.GetFile(strMyPath)
FileSize = objFile.Size
Set objFile = Nothing
Set objFile = objFileSys.OpenTextFile(strMyPath, 1, false, -1)
Response.BinaryWrite(objFile.Read(FileSize))
Set objFile = Nothing
Set objFileSys = Nothing
Response.Flush
%>
Thanks for your help!!! I'd really appreciate it...