荔园在线
荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀
[回到开始]
[上一篇][下一篇]
发信人: gary (★有所属), 信区: Homepage
标 题: 不用组件上载文件代码(二)[转载]
发信站: BBS 荔园晨风站 (Sat Oct 14 08:25:57 2000), 转信
文件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
fi)
' 2. Upload binary/text files of any size to server-side database
(RS("BinFielde
'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
di.
'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"r
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
functio.
'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
use.
TextStream.Write BinaryToString(Field.Value) ' BinaryToString is in upload.
.
TextStream.Close
'Create log line with info about the field
LogLine = LogLine & """" & LogF(Field.name) & LogSeparator & LogF(Field.
Lenr
Next
'Creates line with global request info
pLogLine = pLogLine & Request.ServerVariables("REMOTE_ADDR") & LogSeparator
pLogLine = pLogLine & LogF(Request.ServerVariables("LOGON_USER")) &
LogSeparar
pLogLine = pLogLine & Request.ServerVariables("HTTP_Content_Length") &
LogSepr
pLogLine = pLogLine & OutFolder & LogSeparator
pLogLine = pLogLine & LogLine
pLogLine = pLogLine & LogF(Request.ServerVariables("HTTP_USER_AGENT")) &
LogSr
pLogLine = pLogLine & LogF(Request.ServerVariables("HTTP_COOKIE"))
'Create output line for the client
OutLine = OutLine & "Fields was saved to the <b>" & OutFolder & "</b> folder.
"
DoLog pLogLine, "UP"
OutFolder = Empty 'Clear variables.
SaveUpload = OutLine
End Function
'Writes one log line to the log file
Function DoLog(LogLine, LogPrefix)
if LogFolder = "" then LogFolder = Server.MapPath(".")
Const LogSeparator = ", "
Dim OutStream, FileName
FileName = LogPrefix & Right("0" & Year(Now), 2) & Right("0" & Month(Now),
2)"
Set OutStream = Server.CreateObject("Scripting.FileSystemObject").
OpenTextFil)
OutStream.WriteLine Now() & LogSeparator & LogLine
OutStream = Empty
End Function
'Returns field or "-" if field is empty
Function LogF(ByVal F)
If "" & F = "" Then LogF = "-" Else LogF = "" & F
End Function
'Returns field or "-" if field is empty
Function LogFn(ByVal F)
If "" & F = "" Then LogFn = "-" Else LogFn = formatnumber(F,0)
End Function
Dim Kernel, TickCount, KernelTime, UserTime
Sub BeginTimer()
on error resume next
Set Kernel = CreateObject("ScriptUtils.Kernel") 'Creates the Kernel object
'Get start times
TickCount = Kernel.TickCount
KernelTime = Kernel.CurrentThread.KernelTime
UserTime = Kernel.CurrentThread.UserTime
on error goto 0
End Sub
Sub EndTimer()
'Write times
on error resume next
Response.Write "<br>Script time : " & (Kernel.TickCount - TickCount) & " ms"
Response.Write "<br>Kernel time : " & CLng((Kernel.CurrentThread.KernelTime
-"
Response.Write "<br>User time : " & CLng((Kernel.CurrentThread.UserTime -
Use"
on error goto 0
Kernel = Empty
End Sub
</SCRIPT>
--
I Believe I Can ...
_____________________________________________________
欢迎光临我的主页 Netdreams!
※ 来源:·BBS 荔园晨风站 bbs.szu.edu.cn·[FROM: 192.168.28.86]
[回到开始]
[上一篇][下一篇]
荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店