今天到国外UD网站,www.udzone.com去转了一圈!发现一个很好的文件上传插件,下来一用!
不到一分钟就做出一个简单的文件上传页面!相比较而言,以前做文件上传时,要安装各种组件,还要手工添加代码,且及容易出错!真是我等懒人的福音阿:)
废话少说下面介绍一下如何使用:
1。当然是下它回来拉,地址:http://www.udzone.com/Downloads/PureUpload.mxp
UDzone还有很多好东西,不过最好注册一下先!
2。下下来做什么,当然是安装插件了(不要告诉我你不会安装UD插件哦:)
3。插件装完以后,你会发现在你的UD菜单下会多出
Windows -> Server Behaviors -> Pure ASP File Upload
当然也可以在Server Behaviors窗口中点+号,也会发现 Pure ASP File Upload
4。先在UD里创建一个 RecordSet这是少不了的,然后再分别创建一个
Insert Form 和 Insert File Field 域!当然了,再建两个按钮 Insert Button,分别命名为“上传”,“取消”,OK,各元素基本都齐了!
5。用鼠标点中Insert File Field,然后到Server Behaviors里点中那个+号,再选Pure ASP File Upload
这时弹出个小筐,内容分别是:
(1) Upload Directory 选择你要上传文件存放的目录,默认为当前网页的目录;
(2) Allowed extensions 这里选择上传文件类型,任何/图片/自定义,三种类型;
(3) Form 网页中提交按钮所在的from名;
(4) Go To URL 完成上传后转到的页面地址。
6。全部设置完成,点击确定保存网页,到IE里输出网址,点击“浏览...”按钮随便选个文件,点确定。回来点击“上传”按钮。OK,整个世界清净拉~~~~,跑到你设置的存放上传文件的目录去看看,考!怎么那么快文件就传过去拉:)(本地测试嘛)
OK,文件上传就这么简单,如果你熟练的话,一分钟就搞定!
附:测试上传文件 testupload.asp 源码
testupload.asp
------------------------------------------------------------------------
<%@LANGUAGE="VBSCRIPT"%>
<%
'*** File Upload to: , Extensions: "", Form: form1, Redirect: ""
'*** Pure ASP File Upload -----------------------------------------------------
' Copyright 2000 (c) George Petrov
'
' Script partially based on code from Philippe Collignon
' (http://www.asptoday.com/articles/20000316.htm)
'
' New features from GP:
' * Fast file save with ADO 2.5 stream object
' * new wrapper functions, extra error checking
' * UltraDev Server Behavior extension
'
' Version: 1.5.0
'------------------------------------------------------------------------------
Sub BuildUploadRequest(RequestBin)
'Get the boundary
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
if PosEnd = 0 then
Response.Write "
Form was submitted with no ENCTYPE=""multipart/form-data"""
Response.Write "Please correct the form attributes and try again."
Response.End
end if
boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos = InstrB(1,RequestBin,boundary)
'Get all data inside the boundaries
Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
'Members variable of objects are put in a dictionary object
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Dictionary")
'Get an object name
Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
Pos = InstrB(Pos,RequestBin,getByteString("name="))
PosBeg = Pos+6
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename="))
PosBound = InstrB(PosEnd,RequestBin,boundary)
'Test if object is of file type
If PosFile<>0 AND (PosFile
'Get Filename, content-type and content of file
PosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
FileName = Mid(FileName,InStrRev(FileName,"\")+1)
'Add filename to dictionary object
UploadControl.Add "FileName", FileName
Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
PosBeg = Pos+14
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
'Add content-type to dictionary object
ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "ContentType",ContentType
'Get content of object
PosBeg = PosEnd+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
value = FileName
valueBeg = PosBeg-1
valueLen = PosEnd-Posbeg
Else
'Get content of object
Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
PosBeg = Pos+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
valueBeg = 0
valueEnd = 0
End If
'Add content to dictionary object
UploadControl.Add "value" , value
UploadControl.Add "valueBeg" , valueBeg
UploadControl.Add "valueLen" , valueLen
'Add dictionary object to main dictionary
UploadRequest.Add name, UploadControl
'Loop to next object
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
Loop
End Sub
'String to byte string conversion
Function getByteString(StringStr)
For i = 1 to Len(StringStr)
char = Mid(StringStr,i,1)
getByteString = getByteString & chrB(AscB(char))
Next
End Function
'Byte string to string conversion
Function getString(StringBin)
getString =""
For intCount = 1 to LenB(StringBin)
getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
Next
End Function
Function UploadFormRequest(name)
on error resume next
if UploadRequest.Item(name) then
UploadFormRequest = UploadRequest.Item(name).Item("value")
end if
End Function
'Process the upload
UploadQueryString = Replace(Request.QueryString,"GP_upload=true","")
if mid(UploadQueryString,1,1) = "&" then
UploadQueryString = Mid(UploadQueryString,2)
end if
GP_uploadAction = CStr(Request.ServerVariables("URL")) & "?GP_upload=true"
If (Request.QueryString <> "") Then
if UploadQueryString <> "" then
GP_uploadAction = GP_uploadAction & "&" & UploadQueryString
end if
End If
If (CStr(Request.QueryString("GP_upload")) <> "") Then
GP_redirectPage = ""
If (GP_redirectPage = "") Then
GP_redirectPage = CStr(Request.ServerVariables("URL"))
end if
RequestBin = Request.BinaryRead(Request.TotalBytes)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin
GP_keys = UploadRequest.Keys
for GP_i = 0 to UploadRequest.Count - 1
GP_curKey = GP_keys(GP_i)
'Save all uploaded files
if UploadRequest.Item(GP_curKey).Item("FileName") <> "" then
GP_value = UploadRequest.Item(GP_curKey).Item("value")
GP_valueBeg = UploadRequest.Item(GP_curKey).Item("valueBeg")
GP_valueLen = UploadRequest.Item(GP_curKey).Item("valueLen")
if GP_valueLen = 0 then
Response.Write "An error has occured saving uploaded file!
"
Response.Write "Filename: " & Trim(GP_curPath) & UploadRequest.Item(GP_curKey).Item("FileName") & "
"
Response.Write "File does not exists or is empty.
"
Response.Write "Please correct and try again"
response.End
end if
'Create a Stream instance
Dim GP_strm1, GP_strm2
Set GP_strm1 = Server.CreateObject("ADODB.Stream")
Set GP_strm2 = Server.CreateObject("ADODB.Stream")
'Open the stream
GP_strm1.Open
GP_strm1.Type = 1 'Binary
GP_strm2.Open
GP_strm2.Type = 1 'Binary
GP_strm1.Write RequestBin
GP_strm1.Position = GP_valueBeg
GP_strm1.CopyTo GP_strm2,GP_valueLen
'Create and Write to a File
GP_curPath = Request.ServerVariables("PATH_INFO")
GP_curPath = Trim(Mid(GP_curPath,1,InStrRev(GP_curPath,"/")) & "")
if Mid(GP_curPath,Len(GP_curPath),1) <> "/" then
GP_curPath = GP_curPath & "/"
end if
on error resume next
GP_strm2.SaveToFile Trim(Server.mappath(GP_curPath))& "\" & UploadRequest.Item(GP_curKey).Item("FileName"),2
if err then
Response.Write "An error has occured saving uploaded file!
"
Response.Write "Filename: " & Trim(GP_curPath) & UploadRequest.Item(GP_curKey).Item("FileName") & "
"
Response.Write "Maybe the destination directory does not exist, or you don't have write permission.
"
Response.Write "Please correct and try again"
err.clear
response.End
end if
end if
next
'*** GP NO REDIRECT
end if
if UploadQueryString <> "" then
UploadQueryString = UploadQueryString & "&GP_upload=true"
else
UploadQueryString = "GP_upload=true"
end if
%>
<%
set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_webdata_STRING
Recordset1.Source = "SELECT art_id FROM dbo.article"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 3
Recordset1.Open()
Recordset1_numRows = 0
%>
testupload.asp
<%
Recordset1.Close()
%>