文件上传的问题
日期:2006-09-14 荐:
文件上传的问题请大家推荐一种可以上传文件的方法!组件或无组件只要可以实现文件的上传、和删除的都可以。谢了。最好有实现的代码。上传文件并加入上传信息的实例http://community.csdn.net/Expert/TopicView.asp?id=3531185一般都用这个<SCRIPT RUNAT = SERVER LANGUAGE = VBSCRIPT>'*****************************************''标题: 化境ASP无组件上传类'作者: 稻香老农 2003-1-8'修订: 梁无惧'版本: 2.0'注释: lsh'*****************************************'Dim Data_5xsoftClass upload_5xsoft Dim objForm, objFile, Version'objForm : 表单集(表单名,值)'objFile : 文件集(表单名,值)'Version : 当前版本'用表单名取得文本字符串Public function Form(strForm) strForm = lcase(strForm) if objForm.exists(strForm) then Form = objForm(strForm) else Form = "" end ifend function'用表单名取得上传的文件Public function File(strFile) strFile = lcase(strFile) if objFile.exists(strFile) then 'File是一个FileInfo类型对象 set File = objFile(strFile) else set File = new FileInfo end ifend functionPrivate Sub Class_Initialize Dim RequestData, sStart, vbCrlf, sInfo, iInfoStart, iInfoEnd, tStream, iStart, theFile Dim iFileSize, sFilePath, sFileType, sFormValue, sFileName Dim iFindStart, iFindEnd Dim iFormStart, iFormEnd, sFormName Version = "化境HTTP上传程序 Version 2.0" set objForm = Server.CreateObject("Scripting.Dictionary") set objFile = Server.CreateObject("Scripting.Dictionary") if Request.TotalBytes < 1 then Exit Sub set tStream = Server.CreateObject("adodb.stream") set Data_5xsoft = Server.CreateObject("adodb.stream") Data_5xsoft.Type = 1 Data_5xsoft.Mode =3 Data_5xsoft.Open Data_5xsoft.Write Request.BinaryRead(Request.TotalBytes) Data_5xsoft.Position = 0 RequestData = Data_5xsoft.Read iFormStart = 1 iFormEnd = LenB(RequestData) vbCrlf = chrB(13) & chrB(10) sStart = MidB(RequestData, 1, InStrB(iFormStart, RequestData, vbCrlf) - 1) iStart = LenB (sStart) iFormStart = iFormStart iStart 1 while (iFormStart 10) < iFormEnd iInfoEnd = InStrB(iFormStart, RequestData, vbCrlf & vbCrlf) 3 tStream.Type = 1 tStream.Mode = 3 tStream.Open Data_5xsoft.Position = iFormStart Data_5xsoft.CopyTo tStream, iInfoEnd - iFormStart tStream.Position = 0 tStream.Type = 2 tStream.Charset = "gb2312" sInfo = tStream.ReadText tStream.Close '取得表单项目名称 iFormStart = InStrB(iInfoEnd, RequestData, sStart) iFindStart = InStr(22, sInfo, "name=""", 1) 6 iFindEnd = InStr(iFindStart, sInfo ,"""", 1) sFormName = lcase(Mid(sinfo, iFindStart, iFindEnd - iFindStart)) '如果是文件 if InStr (45, sInfo, "filename=""", 1) > 0 then 'theFile是一个FileInfo类对象 set theFile = new FileInfo '取得文件名和路径 iFindStart = InStr(iFindEnd, sInfo, "filename=""", 1) 10 iFindEnd = InStr(iFindStart, sInfo, """", 1) sFileName = Mid(sinfo, iFindStart, iFindEnd - iFindStart) theFile.FileName = getFileName(sFileName) theFile.FilePath = getFilePath(sFileName) '取得文件类型 iFindStart = InStr(iFindEnd, sInfo, "Content-Type: ", 1) 14 iFindEnd = InStr(iFindStart, sInfo, vbCr) theFile.FileType = Mid (sinfo, iFindStart, iFindEnd - iFindStart) theFile.FileStart = iInfoEnd theFile.FileSize = iFormStart - iInfoEnd -3 theFile.FormName = sFormName if not objFile.Exists(sFormName) then objFile.add sFormName, theFile end if else '如果是表单项目 tStream.Type = 1 tStream.Mode = 3 tStream.Open Data_5xsoft.Position = iInfoEnd Data_5xsoft.CopyTo tStream, iFormStart - iInfoEnd - 3 tStream.Position = 0 tStream.Type = 2 tStream.Charset ="gb2312" sFormValue = tStream.ReadText tStream.Close if objForm.Exists(sFormName) then objForm(sFormName) = objForm(sFormName) & ", " & sFormValue else objForm.Add sFormName, sFormValue end if end if iFormStart = iFormStart iStart 1wend RequestData = "" set tStream = nothingEnd SubPrivate Sub Class_Terminate if Request.TotalBytes > 0 then objForm.RemoveAll objFile.RemoveAll set objForm = nothing set objFile = nothing Data_5xsoft.Close set Data_5xsoft = nothing end ifEnd Sub Private function GetFilePath(FullPath) If FullPath <> "" Then
GetFilePath = left(FullPath, InStrRev(FullPath, "\")) Else GetFilePath = "" End IfEnd function Private function GetFileName(FullPath) If FullPath <> "" Then GetFileName = mid(FullPath, InStrRev(FullPath, "\") 1) Else GetFileName = "" End IfEnd functionEnd ClassClass FileInfo Dim FormName, FileName, FilePath, FileSize, FileType, FileStart Private Sub Class_Initialize FileName = "" FilePath = "" FileSize = 0 FileStart= 0 FormName = "" FileType = "" End Sub '公共方法---保存文件 'FullPath参数传入的是全路径,如是虚拟路径要用Server.MapPath() Public function SaveAs(FullPath) Dim dr, ErrorChar, i SaveAs = true if trim(fullpath) = "" or FileStart = 0 or FileName = "" or right(fullpath, 1) = "/" then exit function end if set dr = CreateObject("Adodb.Stream") dr.Mode = 3 dr.Type = 1 dr.Open Data_5xsoft.position = FileStart Data_5xsoft.copyto dr, FileSize dr.SaveToFile FullPath, 2 dr.Close set dr = nothing SaveAs = false end functionEnd Class</SCRIPT>多看下FAQ谢了,先试试google搜索lyfupload网上有好多啊我知道好多,我只是想多收集一些这方面的资料。看看哪个更好用。呵呵~~!太多了,网上一查就找到
标签: