Transformation ASP No component upload

Source: Internet
Author: User
Tags exit chr file upload version window
Upload | no components

All along, due to the limitations of FileSystemObject, so the biggest problem is the ASP file upload, most of the solution is to install Third-party upload components. There are many problems with third-party components, some components to register, and some components to add his copyright information to the form. There is also the compatibility of components. On the internet also circulated a lot of no component upload code, but can only upload text files, or only to upload files to the database. The author of this period of time in the study of ASP, found that no third-party components can upload any type of file. Wrote this class, to give everyone a convenient, the whole class placed in a file: Upload_5xsoft.inc in the Example directory there is a complete multiple file Upload sample program, you can use directly.

Because of "transformation no component Upload program" problems, many netizens have sent their own modified version, each has characteristics. Here, the author uses the user beam without fear to give a modified version, and then made some changes to solve the original found all the problems (specifically see the description). Upload speed has also been greatly improved.

  Upload_5xsoft.inc

<script Runat=server language=vbscript>

'''''''''''''''''''''''''''''''''''''''''''''''''
'
' Please keep this information: Dao Xiang Old farmer made
'
'''''''''''''''''''''''''''''''''''''''''''''''''

Dim Upfile_5xsoft_stream

Class Upload_5xsoft

Dim form,file,version

Private Sub Class_Initialize
Dim istart,ifilenamestart,ifilenameend,iend,vbenter,iformstart,iformend,thefile
Dim strdiv,mformname,mformvalue,mfilename,mfilesize,mfilepath,idivlen,mstr
Version= "Transformation programming HTTP Upload Program Version 1.0"
If Request.totalbytes<1 then Exit Sub
Set Form=createobject ("Scripting.Dictionary")
Set File=createobject ("Scripting.Dictionary")
Set Upfile_5xsoft_stream=createobject ("ADODB.stream")
Upfile_5xsoft_stream.mode=3
Upfile_5xsoft_stream.type=1
Upfile_5xsoft_stream.open
Upfile_5xsoft_stream.write Request.BinaryRead (request.totalbytes)

VBENTER=CHR (&AMP;CHR) (10)
Idivlen=instring (1,vbenter) +1
Strdiv=substring (1,idivlen)
Iformstart=idivlen
Iformend=instring (Iformstart,strdiv)-1
While Iformstart < Iformend
Istart=instring (Iformstart, "name=" "")
Iend=instring (Istart+6, "" "")
Mformname=substring (istart+6,iend-istart-6)
Ifilenamestart=instring (iend+1, "filename=" "")
If Ifilenamestart>0 and Ifilenamestart<iformend then
Ifilenameend=instring (ifilenamestart+10, "" "")
Mfilename=substring (IFILENAMESTART+10,IFILENAMEEND-IFILENAMESTART-10)
Istart=instring (Ifilenameend+1,vbenter&vbenter)
Iend=instring (Istart+4,vbenter&strdiv)
If Iend>istart Then
Mfilesize=iend-istart-4
Else
Mfilesize=0
End If
Set Thefile=new FileInfo
Thefile.filename=getfilename (Mfilename)
Thefile.filepath=getfilepath (Mfilename)
Thefile.filesize=mfilesize
Thefile.filestart=istart+4
Thefile.formname=formname
File.add Mformname,thefile
Else
Istart=instring (Iend+1,vbenter&vbenter)
Iend=instring (Istart+4,vbenter&strdiv)

If Iend>istart Then
Mformvalue=substring (istart+4,iend-istart-4)
Else
Mformvalue= ""
End If
Form. ADD Mformname,mformvalue
End If

Iformstart=iformend+idivlen
Iformend=instring (Iformstart,strdiv)-1
Wend
End Sub

Private Function subString (Thestart,thelen)
Dim i,c,stemp
Upfile_5xsoft_stream.position=thestart-1
Stemp= ""
For I=1 to TheLen
If Upfile_5xsoft_stream.eos then Exit for
C=ASCB (Upfile_5xsoft_stream.read (1))
If C > 127 Then
If Upfile_5xsoft_stream.eos then Exit for
STEMP=STEMP&CHR (AscW (ChrB (AscB (Upfile_5xsoft_stream.read (1)) &CHRB (c)))
I=i+1
Else
STEMP=STEMP&CHR (c)
End If
Next
Substring=stemp
End Function

Private Function instring (THESTART,VARSTR)
Dim i,j,bt,thelen,str
Instring=0
Str=tobyte (VARSTR)
Thelen=lenb (STR)
For I=thestart to Upfile_5xsoft_stream.size-thelen
If I>upfile_5xsoft_stream.size then Exit Function
Upfile_5xsoft_stream.position=i-1
If AscB (Upfile_5xsoft_stream.read (1)) =ASCB (MidB (str,1)) Then
Instring=i
For j=2 to TheLen
If Upfile_5xsoft_stream.eos Then
Instring=0
Exit for
End If
If AscB (Upfile_5xsoft_stream.read (1)) &LT;&GT;ASCB (MidB (str,j,1)) Then
Instring=0
Exit for
End If
Next
If Instring<>0 then Exit Function
End If
Next
End Function

Private Sub class_terminate 
  form. RemoveAll
  file. RemoveAll
  Set form=nothing
  set file=nothing
  Upfile_5xsoft_stream.close
  Set Upfile_5xsoft_stream=nothing
End Sub
  
 
 private function GetFilePath (fullpath)
  If fullpath <> "" Then
   GetFilePath = Left (Fullpath,instrrev (FullPath, "\")
  Else
   getfilepath = "
  end If
 End  function
 
 private function GetFileName (fullpath)
  If fullpath <> "" Then
   GetFileName = Mid (FullPath, InStrRev (FullPath, "\") +1
  Else
   getfilename = ""
  end If
 End  function

Private function ToByte (STR)
Dim I,icode,c,ilow,ihigh
Tobyte= ""
For I=1 to Len (STR)
C=mid (str,i,1)
Icode =ASC (c)
If icode<0 Then icode = Icode + 65535
If icode>255 Then
Ilow = Left (Hex (ASC (c)), 2)
Ihigh =right (Hex (ASC (c)), 2)
ToByte = ToByte & ChrB ("&h" &ilow) & ChrB ("&h" &ihigh)
Else
ToByte = ToByte & ChrB (AscB (c))
End If
Next
End Function
End Class


Class FileInfo
Dim Formname,filename,filepath,filesize,filestart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
filestart= 0
FormName = ""
End Sub

Public Function SaveAs (fullpath)
Dim dr,errorchar,i
Saveas=1
If trim (fullpath) = "" or filesize=0 or filestart=0 or filename= "" Then Exit function
If Filestart=0 or right (fullpath,1) = "/" Then Exit function
Set Dr=createobject ("ADODB.stream")
Dr. Mode=3
Dr. Type=1
Dr. Open
Upfile_5xsoft_stream.position=filestart-1
Upfile_5xsoft_stream.copyto dr,filesize
Dr. SaveToFile fullpath,2
Dr. Close
Set dr=nothing
Saveas=0
End Function
End Class
</SCRIPT>

  Upfile.asp

<%option explicit%>
<!--#include file= "Upload_5xsoft.inc"-->
<title> File Upload </title>
<body>
<br> transformation File Upload!

</body>

Upfile.htm

<title>untitled document</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<style type= "Text/css" >
<!--
td {FONT-SIZE:9PT}
A {color: #000000; Text-decoration:none}
a:hover {Text-decoration:underline}
. tx {height:16px; width:30px; border-color:black black #000000; border-top-width:0px; border-right-width:0px; Borde r-bottom-width:1px; border-left-width:0px; font-size:9pt; Background-color: #eeeeee; Color: #0000FF}
. bt {font-size:9pt; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; h eight:16px; width:80px; Background-color: #eeeeee; Cursor:hand}
. tx1 {height:20px; width:30px font-size:9pt; border:1px solid; border-color:black black #000000; color: #0000FF}
-->
</style>

<body bgcolor= "#FFFFFF" text= "#000000" >
<form name= "Form1" method= "Post" action= "upfile.asp" enctype= "Multipart/form-data" >
<table border= "1" cellspacing= "0" cellpadding= "0" bordercolorlight= "#000000" bordercolordark= "#CCCCCC" width= "91" Height= ">"
<tr>
&LT;TD align= "left" valign= "Middle" height= "a" width= "a" > </td>
&LT;TD bgcolor= "#CCCCCC" align= "left" valign= "Middle" height= "a" width= ">" File Upload </td>
</tr>
</table>
<br>
<input type= "hidden" name= "act" value= "upload" >
<br>
<table width= "71%" border= "1" cellspacing= "0" cellpadding= "5" align= "center" bordercolordark= "#CCCCCC" bordercolorlight= "#000000" >
<tr bgcolor= "#CCCCCC" >
&LT;TD height= "align=" "left" valign= "Middle" bgcolor= "#CCCCCC" > Transformation Programming World File Upload </td>
</tr>
<tr align= "left" valign= "Middle" bgcolor= "#eeeeee" >
&LT;TD bgcolor= "#eeeeee" height= ">"
<script language= "JavaScript" >
function SetID ()
{
Str= ' <br> ';
if (!window.form1.upcount.value)
window.form1.upcount.value=1;
for (i=1;i<=window.form1.upcount.value;i++)
str+= ' +i+ ': <input type= "file" name= "file ' +i+" "style=" width:400 "class=" tx1 "><br><br>";
window.upid.innerhtml=str+ ' <br> ';
}
</script>
The number of <li> need to upload
<input type= "text" name= "Upcount" class= "TX" value= "1" >
<input type= "button" name= "button" class= "BT" Value= "· Set · " >
</li>
<br>
<br>
<li> Upload to:
<input type= "text" name= "filepath" class= "TX" style= "width:350" value= "" >
</li>
</td>
</tr>
&LT;TR align= "center" valign= "Middle" >
&LT;TD align= "left" id= "Upid" height= "122" > File 1:
<input type= "File" Name= "File1" style= "width:400" class= "tx1" value= "" >
</td>
</tr>
&LT;TR align= "center" valign= "Middle" bgcolor= "#eeeeee" >
&LT;TD bgcolor= "#eeeeee" height= ">"
<input type= "Submit" name= "submit" value= "· Submit • "class=" BT ">
<input type= "reset" name= "Submit2" value= "· Re-"class=" "BT" >
</td>
</tr>
</table>
</form>
</body>
<script language= "JavaScript" >

SetID ();
</script>



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.