How can the following code be modified to restrict the upload file type?

Source: Internet
Author: User
Tags chr strlen
<%
Dim FormData, Formsize, divider, BCRLF
Formsize = Request.TotalBytes
FormData = Request.BinaryRead (formsize)
Bcrlf = ChrB (+) & ChrB (10)
Divider = LeftB (FormData, InStrB (FormData, Bcrlf)-1)
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
Streamobj.close
Streamobj1.close
If savefile <> "" Then
SaveFile = SaveFile & "," & FileName
Else
SaveFile = filename ' shows the filename
End If
Else
If savefile <> "" Then
SaveFile = SaveFile & ", *toobig*"
Else
SaveFile = "*toobig*"
End If
End If
End If
End If
If InStrB (startpos, FormData, divider) < 1 Then

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.