On my web email server, users can download attachments off their email.
When they receive a file name that is not in English, the text gets broken in IE 8/9, but it comes out totally fine in Chrome/Firefox. Here is the code that currently handles the download:
<%
attachfile = request("file")%>
<%
files = Split(attachfile,"\")
Set fso = CreateObject("Scripting.FileSystemObject")
Response.Clear
'Response.CharSet="UTF-8"
Response.ContentType = "application/unknown"
Response.AddHeader "Pragma", "no-cache"
Response.AddHeader "Expires", "0"
Response.AddHeader "Content-Transfer-Encoding", "binary"
Response.AddHeader "Content-Disposition","attachment; filename = " & files(Ubound(files))
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromFile attachfile
Response.BinaryWrite objStream.Read
Response.Flush
objStream.Close : Set objStream = nothing
Set fso = Nothing
%>
</BODY>
</HTML>
So then I changed how the filename was being passed in the content-disposition to the following, hoping in vain that it would encode the string in UTF-8 correctly before saving on the client's computer:
Response.AddHeader "Content-Disposition","attachment; filename = " & Server.URLEncode(files(Ubound(files)))
Now I've solved one problem but I am faced with two new problems -_-
The first problem is that filename no longer gets broken when I download the file in IE 8/9 but it adds a weird [1] or [2] at the end of the file extension. So if I had 파일 1.docx, IE would save the document as 파일 1.docx[1]
The second problem is that in chrome, the browser takes the UTF-8 encoded string literally so it gets saved as 파일%20%1.docx. Note that the non-english part of the file is displayed properly but the empty space shows up as Unicode Character Code 20.
How do I go about solving this issue?