日期:2012-12-09  浏览次数:20764 次

文件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 file is part of 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 you 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 will be saved to the next folder :
Dim LogFolder
LogFolder = Server.MapPath(".")

'********************************** SaveUpload **********************************
'This function creates folder and saves contents of 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 you can only use text files to upload. Save binary files by the function takes undefined results.
    'To upload binary files see ScriptUtilities, http://www.pstruh.cz

    'You 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 only 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 line with info about the field
    LogLine = LogLine & """" & LogF(Field.name) & LogSeparator & LogF(Field.Lengt