The encoding format that the browser can correctly recognize. As long as the corresponding Content-Disposition is set according to this encoding, there should be no garbled Chinese file names. First, the Content-Disposition value can have the following encoding formats: 1. urlencode: Conte... SyntaxHighligh
The encoding format that the browser can correctly recognize. As long as the corresponding Content-Disposition is set according to this encoding, there should be no garbled Chinese file names.
First, the Content-Disposition value can have the following encoding formats:
1. urlencode:
Content-Disposition: attachment; filename = "struts2.0% E4 % B8 % AD % E6 % 96% E6 % 87% E7 % A8 % 8B. chm"
2. Base64 encoding:
Content-Disposition: attachment; filename = "=? UTF8? B? C3RydXRzMi4w5Lit5paH5pWZ56iLLmNobQ =? ="
3. RFC2231 standards:
Content-Disposition: attachment; filename * = UTF-8 ''% E5 % 9B % 9E % E6 % 89% A7.msg
4. File name for direct ISO encoding:
Content-Disposition: attachment; filename = "test .txt"
The corresponding encoding formats supported by browsers are as follows:
1. IE browser, which uses URLEncoder Encoding
2. Opera browser, using filename *
3. Chinese output using ISO encoding in Safari
4. The Chrome browser uses Base64 encoding or ISO encoding for Chinese output.
5. the FireFox browser uses Base64, filename *, or ISO-Encoded chinese output.
New_filename = URLEncoder. encode (filename, "UTF8 ");
// If no UA is available, IE is used for encoding by default, because IE is still the dominant
Rtn = "filename = \" "+ new_filename + "\"";
If (userAgent! = Null)
{
UserAgent = userAgent. toLowerCase ();
// IE browser, which can only be subject to URLEncoder Encoding
If (userAgent. indexOf ("msie ")! =-1)
{
Rtn = "filename = \" "+ new_filename + "\"";
}
// Operabrowser can only use filename *
Else if (userAgent. indexOf ("opera ")! =-1)
{
Rtn = "filename * = UTF-8'' "+ new_filename;
}
// Safari, which can only be output in ISO format
Else if (userAgent. indexOf ("safari ")! =-1)
{
Rtn = "filename = \" "+ new String (filename. getBytes (" UTF-8 ")," ISO8859-1 ") + "\"";
}
// The Chrome browser can only use MimeUtility encoding or ISO encoding for Chinese output
Else if (userAgent. indexOf ("applewebkit ")! =-1)
{
New_filename = MimeUtility. encodeText (filename, "UTF8", "B ");
Rtn = "filename = \" "+ new_filename + "\"";
}
// In FireFox, you can use MimeUtility, filename *, or ISO-Encoded chinese output.
Else if (userAgent. indexOf ("mozilla ")! =-1)
{
Rtn = "filename * = UTF-8'' "+ new_filename;
}
}
Currently, I have tested that Chinese file names can be entered in several browsers.
However, there may be garbled characters in different browser versions .....
Author: xrzs