文章探索:   分类:    关键字:  
  + 栏目导航
  + 相关文章
asp中有关字符编码转换的几个函数
绝妙的asp生成静态页面html函数
Asp计算页面执行时间
一个简单的用存储过程分页
将asp页面转换成htm页面
ASP网站漏洞解析及黑客入侵防范方法
URL编码与SQL注入
几种常用排序算法(asp)
ASP调用带参数存储过程的几种方式
实用的ASP连接数据库的函数
ASP如何获取真实IP地址
ASP中怎么实现SQL数据库备份、恢复
判断Cookies是否处于开启状态
怎样才能将服务器端文件夹下的文件,..
几行Asp代码实现防止表单重复提交
用ASP设计网站在线人数统计程序
asp论坛在线人数统计研究
如何用ASP远程在数据库中创建Table
用ASP调用SQL Server的视图和存储过程
Asp与XML的关系
ASP读取EXCEL
在ASP中使用Oracle数据库技巧
一个通过web.Mail发送邮件的类
几种打开记录集方式的比较
购物车范例(购物车页面 )
如何使用FSO搜索硬盘文件
GB码和BIG5码的互换技术
用ASP开发WEB日期选择器
一个投票系统的源程序(coveryourasp.c..
列出服务器上的打印机


技术教程 -> ASP教程 ->  
一个的无组件上传的ASP代码
来源:转载   人气:767   录入时间:2007-11-8
    <!--#include file="../lib/filelib.asp"-->
   <%
    Response.write "<title>上传文件至当前文件夹</title>"
    Response.Write "<body bgcolor=""#D6D3CE"" leftmargin=""0"" topmargin=""0"" title = "" 请您遵守国家相关法律法规上传文件。上传前请杀毒,否则系统将会自动删除此文件!"">"
   
   '**Start Encode**
   Action=Request("A")
   If Action="UL" Then
    DoUpload Request.Cookies("DAZHOU.NET")("nowpath") & "\"
    'CheckDiskSpace
   ' Response.redirect "fileman.asp"
   Else
    ShowUploadForm
   End If
   
   Set fso=Nothing
   '========================
   SUB ShowUploadForm
   '========================
    Response.write "<Dir><form enctype=multipart/form-data name=fmupload method=Post action=Upload.asp?A=UL><br>"
    If Request("n")<>"" AND IsNumeric(Request("n")) Then Session("NumUploadFields")=CInt(Request("n"))
    For i=1 to 5
    Response.Write "<INPUT type=file name=file"& i & " size=35><br>"
    Next
    Response.Write "<br><center><INPUT type=submit value=""开始上传""> <INPUT type='button' value= '取消上传' onclick='window.close()'> "
    Response.Write "</form>"
   End SUB
   
   '========================
   SUB DoUpload(Dir)
   '========================
    'If NOT Application("Debugging") Then On Error resume next
    StartTime=Now
    RequestBin=Request.BinaryRead(Request.TotalBytes)
    Set UploadRequest=CreateObject("Scripting.Dictionary")
    BuildUploadRequest RequestBin, UploadRequest
    keys=UploadRequest.Keys
    For i=0 to UploadRequest.Count - 1
    curKey=keys(i)
    fName=UploadRequest.Item(curKey).Item("FileName")
   
    If fso.FileExists(Dir & fName) Then fso.deletefile Dir & fName
    If fName<>"" AND NOT fso.FileExists(Dir & fName) Then
    value=UploadRequest.Item(curKey).Item("Value")
    valueBeg=UploadRequest.Item(curKey).Item("ValueBeg")
    valueLen=UploadRequest.Item(curKey).Item("ValueLen")
    TotalULSize=TotalULSize + valueLen
    Set strm1=Server.CreateObject("ADODB.Stream")
    Set strm2=Server.CreateObject("ADODB.Stream")
    strm1.Open
    strm1.Type=1 'Binary
    strm2.Open
    strm2.Type=1 'Binary
    strm1.Write RequestBin
    strm1.Position=ValueBeg
    strm1.CopyTo strm2,ValueLen
    strm2.SaveToFile Dir & fName,2
    Set strm1=Nothing
    Set strm2=Nothing
    End If
    Next
    If Now>StartTime Then Response.Write("<br><br><br><br><center>上传成功!<br>速度: " & Round(TotalULSize/1024/DateDiff("s",StartTime,Now)) &" 千字节/秒" )
    Set UploadRequest=Nothing
   End SUB
   
   '========================
   Sub BuildUploadRequest(RequestBin, UploadRequest)
   '========================
    'Get the boundary
    PosBeg=1
    PosEnd=InstrB(PosBeg,RequestBin,getByteString(chr(13)))
    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<PosBound) Then
    '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
    UploadControl.Add "Value" , Value
    UploadControl.Add "ValueBeg" , ValueBeg
    UploadControl.Add "ValueLen" , ValueLen
    UploadRequest.Add name, UploadControl
    BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
    Loop
   End Sub
   
   '====================================
   Function getByteString(StringStr)
   '====================================
    For i=1 to Len(StringStr)
    char=Mid(StringStr,i,1)
    getByteString=getByteString & chrB(AscB(char))
    Next
   End Function
   
   '====================================
   Function getString(StringBin)
   '====================================
    getString =""
    For intCount=1 to LenB(StringBin)
    getString=getString & chr(AscB(MidB(StringBin,intCount,1)))
    Next
   End Function
   %>
   
   




Copyright(C)2007-2024 广州市佳沛数码科技有限公司 版权所有
公司地址: 广州市荔湾区东漖北路560号511室
电话:020-81803473 传真:020-81544987