- Feb 22, 2005
- 7,280
- 0
- 0
I have a script that allows me to serve up files from a local drive via a web interface, without having to share the folder to IIS directly (as in not just making them links).
The issue I've run into is that many of these files have spaces in the names, which with Firefox causes the name to be chopped at the first space. So I put in some logic to replace spaces with underscores, works great. Except that the interface I'm having to build this into (not my own) uses a frame, and when my script runs the browser detects duplicate header information, which is a no-no, and blocks it from running. It works great in a single browser window, but not in a frame.
I switched to ASPUpload, as their comp seems to work fine, but it has the issue with the filenames (I can't force it to use my string in the header, it always uses the local filename).
What I'd like is in my code to replace the content length in the head with something else completely, it doesn't seem possible to do that though. I can add a content length, but if it's already there then I get blocked.
Any ideas?
The issue I've run into is that many of these files have spaces in the names, which with Firefox causes the name to be chopped at the first space. So I put in some logic to replace spaces with underscores, works great. Except that the interface I'm having to build this into (not my own) uses a frame, and when my script runs the browser detects duplicate header information, which is a no-no, and blocks it from running. It works great in a single browser window, but not in a frame.
I switched to ASPUpload, as their comp seems to work fine, but it has the issue with the filenames (I can't force it to use my string in the header, it always uses the local filename).
What I'd like is in my code to replace the content length in the head with something else completely, it doesn't seem possible to do that though. I can add a content length, but if it's already there then I get blocked.
Any ideas?
Code:
Sub DownloadFile(file)
Dim strAbsFile
Dim strFileExtension
Dim objFSO
Dim objFile
Dim objStream
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(file) Then
Set objFile = objFSO.GetFile(file)
Response.Clear
Response.AddHeader "Content-Disposition", "attachment; filename=" & replace(fileName," ","_")
Response.AddHeader "Content-Length", objFile.Size
Response.ContentType = "application/octet-stream"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
Response.CharSet = "UTF-8"
objStream.LoadFromFile(file)
Response.BinaryWrite(objStream.Read)
objStream.Close
Set objStream = Nothing
Set objFile = Nothing
Else
Response.Clear
Response.Write("No such file exists.")
End If
Set objFSO = Nothing
End Sub
Last edited: