Use text +asp to create a news release system/Picture upload (not I wrote) Upload.inc

Source: Internet
Author: User
Upload <script runat=server language=vbscript>
Function Getupload (FormData)
Dim Datastart,divstr,divlen,datasize,formfielddata
' Delimited sign string (+CRLF)
Divstr = LeftB (FORMDATA,INSTRB (Formdata,str2bin (VbCrLf)) + 1)
' Separating the length of the sign string
Divlen = LenB (DIVSTR)
Posopenboundary = InStrB (FORMDATA,DIVSTR)
Poscloseboundary = InStrB (posopenboundary + 1,formdata,divstr)
Set Fields = CreateObject ("Scripting.Dictionary")

While Posopenboundary > 0 and poscloseboundary > 0
' Name start position (name= "xxxxx"), plus 6 because [name=] length is 6
Fieldnamestart = InStrB (Posopenboundary,formdata,str2bin ("name=")) + 6
Fieldnamesize = InStrB (FIELDNAMESTART,FORMDATA,CHRB)-Fieldnamestart ' (") the ASC value =34
Formfieldname = Bin2str (MidB (formdata,fieldnamestart,fieldnamesize))

' FileName starting position (filename= "xxxxx")
Fieldfilenamestart = InStrB (Posopenboundary,formdata,str2bin ("filename=")) + 10
If Fieldfilenamestart < poscloseboundary and Fieldfilenamestart > Posopenboundary Then
Fieldfilenamesize = InStrB (FIELDFILENAMESTART,FORMDATA,CHRB)-Fieldfilenamestart ' (") the ASC value =34
Formfilename = Bin2str (MidB (formdata,fieldfilenamestart,fieldfilenamesize))
Else
Formfilename = ""
End If

' Content-type starting position (CONTENT-TYPE:XXXXX)
Fieldfilectstart = InStrB (Posopenboundary,formdata,str2bin ("Content-type:")) + 14
If Fieldfilectstart < poscloseboundary and Fieldfilectstart > Posopenboundary Then
Fieldfilectsize = InStrB (Fieldfilectstart,formdata,str2bin (VbCrLf & VbCrLf))-Fieldfilectstart
Formfilect = Bin2str (MidB (formdata,fieldfilectstart,fieldfilectsize))
Else
Formfilect = ""
End If

' Data start position: 2 CRLF Start
Datastart = InStrB (Posopenboundary,formdata,str2bin (VbCrLf & VbCrLf)) + 4
If formfilename <> "" Then
' Data length, minus 1 because of the number of bytes accessed by the data file (may be a problem with the AppendChunk method):
' Because an odd number of bytes of an image is saved to the database, the last character is removed, causing the image to display incorrectly.
This problem does not occur with a data file with an even number of bytes, so you must keep the number of bytes even.
DataSize = InStrB (datastart,formdata,divstr)-DataStart-1
Formfielddata = MidB (formdata,datastart,datasize)
Else
' Data length, minus 2 because there is a CRLF in front of the separator flag string
DataSize = InStrB (datastart,formdata,divstr)-DataStart-2
Formfielddata = Bin2str (MidB (formdata,datastart,datasize))
End If

' Create a dictionary set to store the relevant data for each field in the form
Set Field = Createuploadfield ()
Field.name = Formfieldname
Field.filepath = Formfilename
Field.filename = GetFileName (formfilename)
Field.contenttype = Formfilect
Field.length = LenB (formfielddata)
Field.value = Formfielddata

Fields.Add Formfieldname, Field

Posopenboundary = Poscloseboundary
Poscloseboundary = InStrB (posopenboundary + 1,formdata,divstr)
Wend
Set getupload = Fields
End Function

' Converts a binary string to a normal string function
Function Bin2str (BINSTR)
Dim Varlen,clow,ccc,skipflag
' Chinese character skip flag
Skipflag=0
CCC = ""
If not IsNull (BINSTR) Then
Varlen=lenb (BINSTR)
For I=1 to Varlen
If skipflag=0 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.