No component Upload Instance

Source: Internet
Author: User
Tags define chr file size file upload
Upload | no components

This is from the program I have written before, because this code is written for the overall adult program, so the function is very simple, and there is no strict restrictions on the data uploaded, so it is inevitable that this or that error.

I posted an article mainly to let you understand the idea of no component upload, rather than let everyone use.

<%

' yanhang.00 Upload program V1.0
' 1.0 version of the program is modified from the previous program, but there may still be insufficient, if you find any errors, please write to inform me, thank you!
' Please modify the following information before using it
' At present, I think the biggest disadvantage is that only the system time to define the file name, can not use the source file name, which I will be in the future version of the improvement.
' Enjoy yourself!


' Program making: Yanhang
' Email:yanhang@msn.com
' Technical support:http://yanhang00.yeah.net
' This program to run in the ADO more than 2.5 version of the environment


' #################### #请修改以下信息 #####################################
Dim siteurl,picsavefolder,limitbyte,lsfilename
SiteURL = "http://www.yours.com" ' Website address (no "/" symbol at end)
Picsavefolder = "uploadfile/" Picture Save folder (end with "/" symbol)
Limitbyte = 300 ' File size limit, Unit: K
'######################################################################


' #################### #以下信息请不要修改 #################################

If Request.TotalBytes < Then
%>
<title> File Upload </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<BODY>
<form name= "Form2" Method=post action= "upload.asp" enctype= "Multipart/form-data" >
Please select a file:
<input type= "File" name= "file" >
<input type= "Submit" value= "upload" > Size limit: <%=limitbyte%>k
</FORM>
</BODY>
<%
Else
Dim Contentlen
' Receive form information
Contentlen=request.totalbytes

' Detect file Size
If contentlen>limitbyte*1024 Then
Response.Write "File Over" &limitbyte& K, not allowed to upload! "
Else

Dim content
' Read uploaded file information
Content=request.binaryread (Request.TotalBytes)

' Binary reciprocal conversion function '
Function getbytestring (STRINGSTR)
For I=1 to Len (STRINGSTR)
Char=mid (stringstr,i,1)
GETBYTESTRING=GETBYTESTRING&CHRB (AscB (char))
Next
End Function
Function getString (Stringbin)
getString = ""
For intcount = 1 to LenB (Stringbin)
getString = getString & Chr (AscB (MidB (stringbin,intcount,1))
Next
End Function

' Process data
Dim Upbeg,upend,lineone,linetwo,linethree,line1,line2,line3
Upbeg=1
UPEND=INSTRB (Upbeg,content,getbytestring (Chr (10)))
LINEONE=MIDB (Content,upbeg,upend-upbeg)
Upbeg=upend+1
Line1=lenb (Lineone)
UPEND=INSTRB (Upbeg,content,getbytestring (Chr (10)))
LINETWO=MIDB (Content,upbeg,upend-upbeg)
Upbeg=upend+1
Line2=lenb (Linetwo)
UPEND=INSTRB (Upbeg,content,getbytestring (Chr (13)))
LINETHREE=MIDB (Content,upbeg,upend-upbeg)
Line3=lenb (Linethree)

' Get filename
Dim pp,checknametemp,checklen,checkname,filename
PP=INSTRB (1,linetwo,getbytestring (Chr (46)))
CHECKNAMETEMP=RIGHTB (linetwo,line2-pp+1)
CHECKLEN=INSTRB (1,checknametemp,getbytestring (Chr (34)))
Checkname=getstring (LeftB (checknametemp,checklen-1))

' Detect file suffix
If checkname<> "Content-disposition:form-data; Name= "Then
If checkname= '. txt ' or checkname= '. doc ' or checkname= '. gif ' or checkname= '. jpg ' or ' checkname= '. jpeg ' or ' checkname= '. zip ' O R checkname= ". rar" or checkname= ". bmp" or checkname= ". png" or checkname= ". Tiff" Then

' Define filename
Filename=year (now) &month (now), &day (now), &hour (now) &minute (now) &second

' Upload file
Dim alllen,upstream,upstreamend,file
Alllen=line1+line2+line3+6
Set Upstream=server.createobject ("ADODB.stream")
Set Upstreamend=server.createobject ("ADODB.stream")
Upstream.type=1
Upstreamend.type=1
Upstream.open
Upstreamend.open
Upstream.write Content
Upstream.position=alllen
File=upstream.read (CLng (contentlen-alllen-line1-5))
Upstreamend.write file
Upstreamend.savetofile (Server.MapPath (picsavefolder&filename))
Upstream.close
Upstreamend.close
Set upstream=nothing
Set upstreamend=nothing

Response.Write "File Upload success!" <br> filename: "&siteurl&"/"&picsavefolder&filename

Else
Response.Write "Do not allow uploading" &checkname& "format Files"
End If

Else
Response.Write "You did not fill in the filename"
End If

End If
End If
%>



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.