True no component graphics and text mixed upload, powerful, no database, support Chinese!

Source: Internet
Author: User
Tags chr file size mixed strlen domain domain name
Upload | data | database | No Components | Chinese are inspired by some posts in this forum, so they write this program. The program supports the uploading of any text and binary format files; Support file form field and common form field mixed upload, support Chinese filename, support overwriting upload and file with same name, automatically modify filename, support upload multiple files simultaneously, and multiple file form domain name can be the same; Support upload file size control ... I feel very good about myself yo:
This program does not need any database support, directly upload the file saved to the server specified path.
Test environment: Windows2000 + IIS 5.0 (required for ADO version)
Known bugs: Use the same file table Single-name to upload multiple files at the same time with a unique file name, and there are multiple identical file names on the server, only the first file will be automatically renamed upload success, and then the program error.
The source code is as follows, you are welcome to refer to correct:

FileName: uploadx.asp
<%
Dim FormData, Formsize, divider, BCRLF
Formsize = Request.TotalBytes
FormData = Request.BinaryRead (formsize)
Bcrlf = ChrB (+) & ChrB (10)
Divider = LeftB (FormData, InStrB (FormData, Bcrlf)-1)

' Save the uploaded file under the directory specified by path.
' FormField upload form's ' file ' domain name
' Path to save the file's absolute path to the server, in the form of "D:\path\subpath" or "d:\path\subpath\"
' MaxSize limit the maximum length of uploaded files to KByte
' Savtype how the server saves files:
' 0 unique filename method, automatically renamed if there is the same name;
' 1 Method of error, if have the same name error;
' 2 overwrite method, overwrite original file if have same name
Function SaveFile (Formfilefield, Path, MaxSize, Savtype)
Dim streamobj,streamobj1
Set streamobj = Server.CreateObject ("ADODB. Stream ")
Set StreamObj1 = Server.CreateObject ("ADODB. Stream ")
Streamobj.mode = 3
Streamobj1.mode = 3
Streamobj.type = 1
Streamobj1.type = 1
SaveFile = ""
startpos = LenB (divider) + 2
Formfilefield = Chr (a) & Formfilefield & Chr (34)
If Right (path,1) <> "\" Then
Path = path & "\"
End If
Do While startpos > 0
strlen = InStrB (Startpos, FormData, Bcrlf)-startpos
Searchstr = MidB (FormData, startpos, strlen)
If InStr (Bin2str (SEARCHSTR), Formfilefield) > 0 Then
FileName = Bin2str (GetFileName (Searchstr,path,savtype))
If FileName <> "" Then
Filestart = InStrB (Startpos, FormData, Bcrlf & Bcrlf) + 4
FileLen = InStrB (startpos, FormData, divider)-2-filestart
If FileLen <= maxsize*1024 Then
Filecontent = MidB (FormData, Filestart, FileLen)
Streamobj.open
Streamobj1.open
Streamobj.write FormData
Streamobj.position=filestart-1
Streamobj.copyto Streamobj1,filelen
If Savtype =0 Then
Savtype = 1
End If
Streamobj1.savetofile Path & FileName, Savtype



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.