Some previously collected data---do not upload file code snippets without components (i)

Source: Internet
Author: User
Tags servervariables
Here are a series of files that can be uploaded using pure ASP code without components
Oh, I think this will give a lot of users have a personal homepage to bring great convenience.
This pure ASP code consists of three included files, and the code uses only the FileSystemObject
and direction two ASP intrinsic objects. Without the need for any additional components, note that in order to ensure
The source of this code, I did not modify anywhere in the code.
Hope to be able to help you:
File Fupload.inc
<script Runat=server language=vbscript>
' Sample multiple binary files upload via asp-upload include
' c1997-1999 Antonin Foller, Pstruh Software, http://www.pstruh.cz
' The Scriptutilities Library
' The file enables HTTP upload to ASP without any components.
' But There is a small problem-asp does not allow save binary data to the disk.
' So your can use the upload for:
' 1. Upload small text (or HTML) files to Server-side disk (Save the data by filesystem object)
' 2. Upload binary/text Files of any size to Server-side database (RS ("Binfield") = Upload ("FormField"). Value


' Limit of upload size
Dim Uploadsizelimit

' ********************************** getupload **********************************
' This function reads the all form fields from binary input and returns it as a Dictionary object.
' The Dictionary object containing form fields. Each form field was represented by six values:
'. Name Name of the form field (<input name= "...") Type= "File,..." >)
'. Contentdisposition = Content-disposition of the form field
'. FileName = Source file name for <input type=file>
'. ContentType = Content-type for <input type=file>
'. Value = Binary value of the source field.
'. Length = Len of the binary data field
Function Getupload ()
Dim result
Set result = Nothing
If Request.ServerVariables ("request_method") = "post" Then ' Request method must is ' post '
Dim CT, PosB, boundary, Length, PosE
CT = Request.ServerVariables ("Http_content_type") ' reads Content-type header
If LCase (Left (CT,) = "Multipart/form-data" Then ' content-type header must to be "Multipart/form-data"
' This is upload request.
' Get the boundary and length from Content-type header
PosB = InStr (LCase (CT), "boundary=") ' finds boundary
If PosB > 0 Then boundary = Mid (CT, PosB + 9) ' Separetes boundary
Length = CLng (Request.ServerVariables ("Http_content_length")) ' Get Content-length header
If "" & Uploadsizelimit<> "" Then
Uploadsizelimit = CLng (uploadsizelimit)
If Length > Uploadsizelimit Then
' On Error Resume Next ' clears the input buffer
' Response. AddHeader "Connection", "Close"
' On Error Goto 0
Request.BinaryRead (Length)
Err.Raise 2, "Getupload", "Upload Size" & FormatNumber (length,0) & "B exceeds limit of" & FormatNumber (Uploa dsizelimit,0) & "B"
Exit function
End If
End If

If Length > 0 and Boundary <> "Then ' Are there required informations about upload?"
Boundary = "--" & Boundary
Dim Head, Binary
Binary = Request.BinaryRead (Length) ' reads Binary data from client

' Retrieves the upload fields from binary data
Set result = Separatefields (Binary, boundary)
Binary = Empty ' Clear variables
Else
Err.Raise, "Getupload", &



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.