Some of the previously collected data---Upload file code without components (ii)

Source: Internet
Author: User
Tags log servervariables
File Futils.inc
<script Runat=server language=vbscript>
' True pureasp upload-enables save of uploaded text fields to the disk.
' 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

' All uploaded files and log file would be saved to the next folder:
Dim LogFolder
LogFolder = Server.MapPath (".")

' ********************************** saveupload **********************************
' This function creates folder and saves contents's the source fields to the disk.
' The fields are saved as files with names of Form-field names.
' Also writes one line to the log file with basic informations about upload.
Function saveupload (Fields, Destinationfolder, LogFolder)
If Destinationfolder = "" Then Destinationfolder = Server.MapPath (".")

Dim Uploadnumber, Outfilename, FS, Outfolder, Timename, Field
Dim logline, Plogline, OutLine

' Create Unique Upload folder
Application.Lock
If Application ("uploadnumber") = "" Then
Application ("Uploadnumber") = 1
Else
Application ("Uploadnumber") = Application ("Uploadnumber") + 1
End If
Uploadnumber = Application ("Uploadnumber")
Application.UnLock

Timename = Right ("0" & Year (now), 2) & Right ("0" & Month (now), 2) & Right ("0" & Day (now), 2) & "_" & Right ("0" & Hour (now), 2) & Right ("0" & Minute (now), 2) & Right ("0" & Second (now), 2) & "-" & Uploadnumber
Set FS = CreateObject ("Scripting.FileSystemObject")
Set Outfolder = FS. CreateFolder (Destinationfolder + "\" + timename)

Dim TextStream
' Save the uploaded fields and create log line
For each Field in Fields.items
' Write content ' of the field to the disk
'!!!! This function uses FileSystemObject to save the file. !!!!!
' So can I use the text files to upload. Save binary files by the function takes undefined results.
' To upload binary files scriptutilities, http://www.pstruh.cz

' can save files with original file names:
' Set TextStream = FS. CreateTextFile (Outfolder & "\" & Field.filename)

' Or with names of the ' fields
Set TextStream = FS. CreateTextFile (Outfolder & "\" & Field.name & ".")

' And this is the problem why a short text files-binarytostring uses Char-to-char conversion. It takes a lot of computer time.
Textstream.write binarytostring (field.value) ' binarytostring is in Upload.inc.
Textstream.close


' Create log ' with info about the field
Logline = logline & "" "& Logf (field.name) & Logseparator & Logf (field.length) & Logseparator & L OgF (field.contentdisposition) & Logseparator & Logf (field.filename) & Logseparator & Logf ( Field.contenttype) & "" "& Logseparator
Next

' creates line with global request info
Plogline = plogline & Request.ServerVariables ("REMOTE_ADDR") & Logseparator
Plogline = plogline & Logf (Request.ServerVariables ("LOGON_USER")) & Logseparator
Plogline = plogline & Request.ServerVariables ("Http_content_length") & Logseparator
Plogline = plogline & Outfolder & Logseparator
Plogline = plogline & logline
Plogline = plogline & Logf (Request.ServerVariables ("Http_user_agent")) &



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.