主题:  怎么修改才能让这段代码支持中文文件名?

haj

职务:普通成员
等级:1
金币:0.0
发贴:40
注册:2002/2/13 14:35:11
#12002/12/7 13:17:23
用英文的文件名都很正常,都可以把文件名写入数据库,但是要用的是中文文件名的话,则上传之后数据库中文件名列为空~~我想知道怎么修改这段代码才能让它支持中文文件名,才能正常上传中文文件名文件

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>

<%
set rs1 = Server.CreateObject("ADODB.Recordset")
rs1.ActiveConnection = MM_updb_STRING
rs1.Source = "SELECT * FROM fileupload"
rs1.CursorType = 0
rs1.CursorLocation = 2
rs1.LockType = 3
rs1.Open()
rs1_numRows = 0
%>
<%
'BLOB Upload by James M. Illson - DataCertain.com
%>
<%
BLOB_QueryString = Replace(Request.QueryString,"BLOB_upload","")
If Mid(BLOB_QueryString,1,1) = "&" Then
    BLOB_QueryString = Mid(BLOB_QueryString,2)
End If

BLOB_Upload = CStr(Request.ServerVariables("URL")) & "?BLOB_upload"
If (Request.QueryString <> "") Then
If BLOB_QueryString <> "" Then
     BLOB_Upload = BLOB_Upload & "&" & BLOB_QueryString
End If

Response.Buffer = True
Response.Clear
byteCount = Request.TotalBytes

RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin
End If
%>
<%
'Following functions are from Philippe Collignon's article at ASP Today:
'http://www.asptoday.com
%>
<%
Sub BuildUploadRequest(RequestBin)
'Get the boundary
on error resume next
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos = InstrB(1,RequestBin,boundary)
'Get all data inside the boundaries
Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
    'Members variable of objects are put in a dictionary object
    Dim UploadControl
    Set UploadControl = CreateObject("Scripting.Dictionary")
    'Get an object name
    Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
    Pos = InstrB(Pos,RequestBin,getByteString("name="))
    PosBeg = Pos+6
    PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
    Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
    PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename="))
    PosBound = InstrB(PosEnd,RequestBin,boundary)
    'Test if object is of file type
    If PosFile<>0 AND (PosFile        'Get Filename, content-type and content of file
        PosBeg = PosFile + 10
        PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
        FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
        'Add filename to dictionary object
        UploadControl.Add "FileName", FileName
        Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
        PosBeg = Pos+14
        PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
        'Add content-type to dictionary object
        ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
        UploadControl.Add "ContentType",ContentType
        'Get content of object
        PosBeg = PosEnd+4
        PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
        value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
        Else
        'Get content of object
        Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
        PosBeg = Pos+4
        PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
        value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
    End If
    'Add content to dictionary object
UploadControl.Add "value" , value    
    'Add dictionary object to main dictionary
UploadRequest.Add name, UploadControl    
    'Loop to next object
    BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
Loop

contentType = UploadRequest.Item("file_field").Item("ContentType")
filepathname = UploadRequest.Item("file_field").Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
picture = UploadRequest.Item("file_field").Item("value")
'For additional inputs add line like below where
'"txtDescription" is name of input. Also add additional
'line to insert field into database
'strDescription = UploadRequest.Item("txtDescription").Item("value") 'Sample 1

Response.ContentType = contentType
picturechunk = picture & chrB(0)

rs1.AddNew
rs1.Fields("File_blob").appendChunk picturechunk
rs1.Fields("File_type") = contentType
rs1.Fields("File_name") = filename
'Add new fields here for inserting into database, see above
'rs1.Fields("Description") = strDescription 'Sample 1
rs1.Update

Response.Redirect("downlist.asp")

End Sub
%>
<%
'String to byte string conversion
Function getByteString(StringStr)
For i = 1 to Len(StringStr)
    char = Mid(StringStr,i,1)
    getByteString = getByteString & chrB(AscB(char))
Next
End Function

'Byte string to string conversion
Function getString(StringBin)
getString =""
For intCount = 1 to LenB(StringBin)
    getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
Next
End Function
%>












<%
rs1.Close()
set rs1=nothing
%>