Asp file batch Upload

Source: Internet
Author: User
Tags file upload

 Keywords:Asp batch Upload   Asp image batch Upload    Upload files in batchesAsp file UploadAsp file upload codeBatch upload of php documents,

Now, let's look at the code and method for uploading files in batches. First, we use three files,Upload_5xsoft.inc, upload. asp, and up. asp files. Below we will describe these three files one by one and paste the corresponding code:

Let's take a look at upload_5xsoft.inc. I won't talk about why the file extension is inc here. I don't know why I can search for it on this site.

<Script runat = server language = VBSCRIPT>
Dim Data_5xsoft
 
Class upload_5xsoft
    
Dim objForm, objFile, Version
 
Public function Form (strForm)
StrForm = lcase (strForm)
If not objForm. exists (strForm) then
Form = ""
Else
Form = objForm (strForm)
End if
End function
 
Public function File (strFile)
StrFile = lcase (strFile)
If not objFile. exists (strFile) then
Set File = new FileInfo
Else
Set File = objFile (strFile)
End if
End function
 
 
Private Sub Class_Initialize
Dim RequestData, sStart, vbCrlf, sInfo, iInfoStart, iInfoEnd, tStream, iStart, theFile
Dim iFileSize, sFilePath, sFileType, sFormValue, sFileName
Dim iFindStart, iFindEnd
Dim iFormStart, iFormEnd, sFormName
Version = "Version 2.0"
Set objForm = Server. CreateObject ("Scripting. Dictionary ")
Set objFile = Server. CreateObject ("Scripting. Dictionary ")
If Request. TotalBytes <1 then Exit Sub
Set tStream = Server. CreateObject ("adodb. stream ")
Set Data_5xsoft = Server. CreateObject ("adodb. stream ")
Data_5xsoft.Type = 1
Data_5xsoft.Mode = 3
Data_5xsoft.Open
Data_5xsoft.Write Request. BinaryRead (Request. TotalBytes)
Data_5xsoft.Position = 0
RequestData = Data_5xsoft.Read
 
IFormStart = 1
IFormEnd = LenB (RequestData)
VbCrlf = chrB (13) & chrB (10)
SStart = MidB (RequestData, 1, Region B (iFormStart, RequestData, vbCrlf)-1)
IStart = LenB (sStart)
IFormStart = iFormStart + iStart + 1
While (iFormStart + 10) <iFormEnd
IInfoEnd = InStrB (iFormStart, RequestData, vbCrlf & vbCrlf) + 3
TStream. Type = 1
TStream. Mode = 3
TStream. Open
Data_5xsoft.Position = iFormStart
Data_5xsoft.CopyTo tStream, iInfoEnd-iFormStart
TStream. Position = 0
TStream. Type = 2
TStream. Charset = "gb2312"
SInfo = tStream. ReadText
TStream. Close
'Get the form project name
IFormStart = required B (iInfoEnd, RequestData, sStart)
IFindStart = InStr (22, sInfo, "name =", 1) + 6
IFindEnd = InStr (iFindStart, sInfo, ", 1)
SFormName = lcase (Mid (sinfo, iFindStart, iFindEnd-iFindStart ))
'If it is a file
If InStr (45, sInfo, "filename =", 1)> 0 then
Set theFile = new FileInfo
'Get the file name
IFindStart = InStr (iFindEnd, sInfo, "filename =", 1) + 10
IFindEnd = InStr (iFindStart, sInfo, ", 1)
SFileName = Mid (sinfo, iFindStart, iFindEnd-iFindStart)
TheFile. FileName = getFileName (sFileName)
TheFile. FilePath = getFilePath (sFileName)
'Get file type
IFindStart = InStr (iFindEnd, sInfo, "Content-Type:", 1) + 14
IFindEnd = InStr (iFindStart, sInfo, vbCr)
TheFile. FileType = Mid (sinfo, iFindStart, iFindEnd-iFindStart)
TheFile. FileStart = iInfoEnd
TheFile. FileSize = iFormStart-iInfoEnd-3
TheFile. FormName = sFormName
If not objFile. Exists (sFormName) then
ObjFile. add sFormName, theFile
End if
Else
'For a form project
TStream. Type = 1
TStream. Mode = 3
TStream. Open
Data_5xsoft.Position = iInfoEnd
Data_5xsoft.CopyTo tStream, iFormStart-iInfoEnd-3
TStream. Position = 0
TStream. Type = 2
TStream. Charset = "gb2312"
SFormValue = tStream. ReadText
TStream. Close
If objForm. Exists (sFormName) then
ObjForm (sFormName) = objForm (sFormName) & "," & sFormValue
Else
ObjForm. Add sFormName, sFormValue
End if
End if
IFormStart = iFormStart + iStart + 1
Wend
RequestData = ""
Set tStream = nothing
End Sub
 
Private Sub Class_Terminate
If Request. TotalBytes> 0 then
ObjForm. RemoveAll
ObjFile. RemoveAll
Set objForm = nothing
Set objFile = nothing
Data_5xsoft.Close
Set Data_5xsoft = nothing
End if
End Sub
      
  
Private function GetFilePath (FullPath)
If FullPath <> "" Then
GetFilePath = left (FullPath, limit Rev (FullPath ,"\"))
Else
GetFilePath = ""
End If
End function
  
Private function GetFileName (FullPath)
If FullPath <> "" Then
GetFileName = mid (FullPath, limit Rev (FullPath, "\") + 1)
Else
GetFileName = ""
End If
End function
End Class
 
Class FileInfo
Dim FormName, FileName, FilePath, FileSize, FileType, FileStart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart = 0
FormName = ""
FileType = ""
End Sub
    
Public function SaveAs (FullPath)
Dim dr, ErrorChar, I
SaveAs = true
If trim (fullpath) = "" or FileStart = 0 or FileName = "" or right (fullpath, 1) = "/" then exit function
Set dr = CreateObject ("Adodb. Stream ")
Dr. Mode = 3
Dr. Type = 1
Dr. Open
Data_5xsoft.position = FileStart
Data_5xsoft.copyto dr, FileSize
Dr. SaveToFile FullPath, 2
Dr. Close
Set dr = nothing
SaveAs = false
End function
End Class
</SCRIPT>

This is a file Upload class. It will be used in our up. asp file.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.