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

ASP
Adodb.Command 平时很少注意到的一个参数
Asp.Net控件加载错误的解决方法
远程连接access数据库的方法
创建具有JScript的HTML的XMLHTTP
在Asp中如何快速优化分页的技巧
用VB生成DLL封装ASP代码,连接数据库
RS.OPEN SQL,CONN,A,B 全接触
利用adodb.stream直接下载任何后缀的文件(防盗链)
用ASP编程控制在IIS建立Web站点的程序代码
使用VBScript操作Html复选框(CheckBox)控件
把文章内容中涉及到的图片自动保存到本地服务器
两个不同数据库表的分页显示解决方案
使用组件封装数据库操作(一)
使用组件封装数据库操作(二)
如何在pb中创建COM组件,并在asp中调用并返回结果集?
用ASP和Microsoft.XMLDOM分析远程XML文件
浅谈无刷新取得远程数据技术
将ASP纪录集输出成n列的的表格形式显示的方法
在ASP中通过oo4o连接Oracle数据库的例子
Server Application Error详细解决办法

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 96 ::
收藏到网摘: 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