主题:  谁能告诉我这个子程序中的参数是怎么被指定的

laohu1980

职务:普通成员
等级:1
金币:0.0
发贴:20
#12003/6/5 9:19:37
estBin这个参数已经被指定为客户端上传的数据,但其余的参数我不知道是怎么被指定的,请高手指教,谢谢

Sub BuildUploadRequest(RequestBin,UploadDirectory,storeType,sizeLimit,nameConflict)
'Get the boundary
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
if PosEnd = 0 then
Response.Write "Form was submitted with no ENCTYPE=""multipart/form-data""
"
Response.Write "Please correct the form attributes and try again."
Response.End
end if
'Check ADO Version
    set checkADOConn = Server.CreateObject("ADODB.Connection")
    adoVersion = CSng(checkADOConn.Version)
    set checkADOConn = Nothing
    if adoVersion < 2.5 then
Response.Write "You don't have ADO 2.5 installed on the server.
"
Response.Write "The File Upload extension needs ADO 2.5 or greater to run properly.
"
Response.Write "You can download the latest MDAC (ADO is included) from www.microsoft.com/data
"
Response.End
    end if        
'Check content length if needed
    Length = CLng(Request.ServerVariables("HTTP_Content_Length")) 'Get Content-Length header
    If "" & sizeLimit <> "" Then
sizeLimit = CLng(sizeLimit)
If Length > sizeLimit Then
Request.BinaryRead (Length)
Response.Write "Upload size " & FormatNumber(Length, 0) & "B exceeds limit of " & FormatNumber(sizeLimit, 0) & "B"
Response.End
End If
End If
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))
FileName = Mid(FileName,InStrRev(FileName,"\")+1)
'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 = FileName
valueBeg = PosBeg-1
valueLen = 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))
valueBeg = 0
valueEnd = 0
End If
'Add content to dictionary object
UploadControl.Add "value" , value    
UploadControl.Add "valueBeg" , valueBeg
UploadControl.Add "valueLen" , valueLen    
'Add dictionary object to main dictionary
UploadRequest.Add name, UploadControl    
'Loop to next object
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
Loop

GP_keys = UploadRequest.Keys
for GP_i = 0 to UploadRequest.Count - 1
GP_curKey = GP_keys(GP_i)
'Save all uploaded files
if UploadRequest.Item(GP_curKey).Item("FileName") <> "" then
GP_value = UploadRequest.Item(GP_curKey).Item("value")
GP_valueBeg = UploadRequest.Item(GP_curKey).Item("valueBeg")
GP_valueLen = UploadRequest.Item(GP_curKey).Item("valueLen")

if GP_valueLen = 0 then
Response.Write "An error has occured saving uploaded file!

"
Response.Write "Filename: " & Trim(GP_curPath) & UploadRequest.Item(GP_curKey).Item("FileName") & "
"
Response.Write "File does not exists or is empty.
"
Response.Write "Please correct and try again"
          response.End
     end if

'Create a Stream instance
Dim GP_strm1, GP_strm2
Set GP_strm1 = Server.CreateObject("ADODB.Stream")
Set GP_strm2 = Server.CreateObject("ADODB.Stream")

'Open the stream
GP_strm1.Open
GP_strm1.Type = 1 'Binary
GP_strm2.Open
GP_strm2.Type = 1 'Binary

GP_strm1.Write RequestBin
GP_strm1.Position = GP_valueBeg
GP_strm1.CopyTo GP_strm2,GP_valueLen

'Create and Write to a File
GP_curPath = Request.ServerVariables("PATH_INFO")
GP_curPath = Trim(Mid(GP_curPath,1,InStrRev(GP_curPath,"/")) & UploadDirectory)
if Mid(GP_curPath,Len(GP_curPath),1) <> "/" then
GP_curPath = GP_curPath & "/"
end if
GP_CurFileName = UploadRequest.Item(GP_curKey).Item("FileName")
GP_FullFileName = Trim(Server.mappath(GP_curPath))& "\" & GP_CurFileName
'Check if the file alreadu exist
GP_FileExist = false
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(GP_FullFileName)) Then
GP_FileExist = true
End If
if nameConflict = "error" and GP_FileExist then
Response.Write "File already exists!

"
Response.Write "Please correct and try again"
                GP_strm1.Close
                GP_strm2.Close
          response.End
end if
if ((nameConflict = "over" or nameConflict = "uniq") and GP_FileExist) or (NOT GP_FileExist) then
if nameConflict = "uniq" and GP_FileExist then
Begin_Name_Num = 0
while GP_FileExist
Begin_Name_Num = Begin_Name_Num + 1
GP_FullFileName = Trim(Server.mappath(GP_curPath))& "\" & fso.GetBaseName(GP_CurFileName) & "_" & Begin_Name_Num & "." & fso.GetExtensionName(GP_CurFileName)
GP_FileExist = fso.FileExists(GP_FullFileName)
wend
UploadRequest.Item(GP_curKey).Item("FileName") = fso.GetBaseName(GP_CurFileName) & "_" & Begin_Name_Num & "." & fso.GetExtensionName(GP_CurFileName)
                    UploadRequest.Item(GP_curKey).Item("value") = UploadRequest.Item(GP_curKey).Item("FileName")
end if
on error resume next
GP_strm2.SaveToFile GP_FullFileName,2
if err then
Response.Write "An error has occured saving uploaded file!

"
Response.Write "Filename: " & Trim(GP_curPath) & UploadRequest.Item(GP_curKey).Item("FileName") & "
"
Response.Write "Maybe the destination directory does not exist, or you don't have write permission.
"
Response.Write "Please correct and try again"
         err.clear
                GP_strm1.Close
                GP_strm2.Close
          response.End
     end if
            GP_strm1.Close
            GP_strm2.Close
            if storeType = "path" then
                UploadRequest.Item(GP_curKey).Item("value") = "d:\xfrbtg\image\" & UploadRequest.Item(GP_curKey).Item("value")
            end if
on error goto 0
end if
end if
next

End Sub



缺缺

职务:管理员
等级:8
金币:41.0
发贴:9620
#22003/6/5 11:20:08
这个是你调用这个程序是指定的,不是他自己指定的。如果是一个固定的值或者函数那都无须参数了。