当前位置: 首页 > 图文教程 > 网络编程 > ASP > 多表单域无组件文件上传的例子

ASP
保护 XML Web 服务免受黑客攻击
开发BtoC电子商务系统(ASP.NET)
用asp.net实现的把本文推荐给好友功能
尝尝ASP.NET中的小甜饼
web.config一个中文解释
使用ASP.NET加密口令
在SQL Server中保存和输出图片
ASP 中健壮的页结构的异常处理
如何使你的机器运行ASP?
asp(Active Server Page)的语言特性
关于inc文件
IE4 的 模 式 对 话 框 设 计
亲密接触ASP.net(6)
亲密接触ASP.Net(7)
用ASP.Net写一个发送ICQ信息的程序
用ASP.Net编写的查询域名的程序
使用 ASP+ 列表绑定控件(上)
使用 ASP+ 列表绑定控件(中)
使用 ASP+ 列表绑定控件(下)
揭开ASP神秘面纱(1)

ASP 中的 多表单域无组件文件上传的例子


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 172 ::
收藏到网摘: n/a

  最近经常有人问到这类问题,在此转贴一下,内容:


1。数据库表结构(Access):
UserID:Text(保存上传文件的用户ID)
FileContentType:Text(用来保存上传文件的类型,eg:"Application/msword",主要用来使用户能正确下载此文件)
FileContent:OLE Object(保存文件数据)

2。HTML文件
muploadfile.htm
<Form name="upload_file" enctype="multipart/form-data" action="muploadfile.asp" method=post>
<input type=hidden name="UserID" value="abc">
<input type=hidden name="FileUploadStart"> '这里用来表示开始文件数据上传
File to send: <BR>
<INPUT TYPE="file" name="file_up" size="30"><br>
<INPUT TYPE="file" name="file_up" size="30"><br>
<input type=hidden name="FileUploadEnd"> '这里用来表示文件数据结束
<input type=submit value=Submit>
</Form>

3。ASP文件
muploadfile.asp

<%
Response.Expires=0
Function bin2str(binstr)
    Dim varlen,clow,ccc,skipflag

    skipflag=0
    ccc = ""
    If Not IsNull(binstr) Then
        varlen=LenB(binstr)
        For i=1 To varlen
            If skipflag=0 Then
                clow = MidB(binstr,i,1)
                If AscB(clow) > 127 Then
                    ccc =ccc & Chr(AscW(MidB(binstr,i+1,1) & clow))
                    skipflag=1
                Else
                    ccc = ccc & Chr(AscB(clow))
                End If
            Else
                skipflag=0
            End If
        Next
    End If
    bin2str = ccc
End Function


varByteCount = Request.TotalBytes
bnCRLF = chrB( 13 ) & chrB( 10 )
binHTTPHeader=Request.BinaryRead(varByteCount)        
Divider = LEFTB( binHTTPHeader,  INSTRB( binHTTPHeader, bnCRLF ) - 1 )

'开始读非文件域的数据
Do while lenB(binHTTPHeader)>46
    
    binHeaderData = LeftB(binHTTPHeader, INSTRB( binHTTPHeader, bnCRLF & bnCRLF )-1)
    strHeaderData=bin2str(binHeaderData)

    lngFieldNameStart=Instr(strHeaderData,"name="&chr(34))+Len("name="&chr(34))
    lngFieldNameEnd=Instr(lngFieldNameStart,strHeaderData,chr(34))
    
    
    strFieldName=Mid(strHeaderData,lngFieldNameStart,lngFieldNameEnd-lngFieldNameStart)
    strFieldName=Trim(strFieldName)
    strFieldName=Replace(strFieldName,vbcrlf,vbnullstring)
    
        '判断文件数据时候开始
    If strComp(strF