文章·资料 电脑软件 手机软件 网站源码




    本 站 搜 索
   推 荐 文 章        More...
华硕易电脑(ASUS Eee PC 10..
先来段开场白:为了外出携带方便..
Acronis True Image 使用..
  一款可以在Windows下使用..
Norton Ghost 使用详解
一、分区备份   使用Ghost..
    文 章 阅 读 排 行
“啊估文章软件站”网站系..
一、调试测试网站系统时,如何..
关于 Firefox 在中国持续..
亲爱的 Firefox 用户及 Firefox..
向日葵远程控制软件,设置..
向日葵远程控制软件有个人版和..
夸克网盘新用户注册如何获..
夸克网盘,新用户注册如何获得1..
FileZilla Server 设置参考
FileZilla Server 启动界面 ..
PakePlus 构建 APP 需要 Gi..
PakePlus 是一个基于 Rust Taur..
电脑显示器使用 HDMI 数据..
如果电脑显示器使用 HDMI 数据..
ASP/JavaScript:不刷新页..
function GuReturnElement(..
分享几个免费申请 SSL 证..
DigiCert 原 Symantec(赛门铁..
关闭微信的个性化推荐广告
有网友说到,微信的初衷是拉近..
 文 章 信 息
无组件实现文件上传/下载
评论()〗〖留言〗〖收藏
〖文章分类:电脑·手机·网络 / 网站设计·开发·优化〗〖阅读选项

'==================================================================
'
'  用ASP实现无组件上传/下载文件
'
' 功能简介
' 将上传的文件数据保存到数据库中,可以处理表单中的多个上传文件的情况
' 适用于各种数据库,使用ADO的方法连接数据库
' 本示例中使用的是ACCESS数据库:zj.mdb
' 表:tb_img(id int(自增列),path text(255) 保存上传文件的目录
' ,fname text(250) 保存上传的文件名,type test(250) 保存上传文件的类型
'        ,img ole对象 保存上传的文件内容
'
'
'==================================================================


'==================================================================
'
' 上传文件的HTML页: zj_up.htm
'
'==================================================================
<html>
<head>
<title>文件上传保存到数据库中</title>
</head>
<body>
<form name="form1" enctype="multipart/form-data" method="post" action="zj_up.asp">
  <p>
    <input type="file" name="file">
    <input type="submit" name="Submit" value="上传">
  </p>
</form>
</body>
</html>


'==================================================================
'
'  上传文件保存到数据库的ASP页: zj_up.asp
'
'==================================================================
<%
Response.Expires=0
Function f_Bin2Str(ByVal sBin)
    Dim iI, iLen, iChr, iRe      
    iRe = ""
    If Not IsNull(sBin) Then
        iLen = LenB(sBin)
        For iI = 1 To iLen
            iChr = MidB(sBin, iI, 1)
            If AscB(iChr) > 127 Then
                iRe = iRe & Chr(AscW(MidB(sBin, iI + 1, 1) & iChr))
                iI = iI + 1
            Else
                iRe = iRe & Chr(AscB(iChr))
            End If
        Next
    End If    
    f_Bin2Str = iRe
End Function
iConcStr = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False" & _
";Data Source=" & server.mappath("zj.mdb")
iSql="tb_img"
set iRe=Server.CreateObject("ADODB.Recordset")
iRe.Open iSql,iConcStr,1,3
iLen=Request.TotalBytes
sBin=Request.BinaryRead(iLen)
iCrlf1 = ChrB(13) & ChrB(10)
iCrlf2 = iCrlf1 & iCrlf1
iLen = InStrB(1, sBin, iCrlf1) - 1
iSpc = LeftB(sBin, iLen)
sBin = MidB(sBin, iLen + 34)
iPos1 = InStrB(sBin, iCrlf2) - 1
While iPos1 > 0
iStr = f_Bin2Str(LeftB(sBin, iPos1))
iPos1 = iPos1 + 5
iPos2 = InStrB(iPos1, sBin, iSpc)

iPos3 = InStr(iStr, "; 200412213005.htm=""") + 12
If iPos3 > 12 Then
  iStr = Mid(iStr, iPos3)
  iPos3 = InStr(iStr, Chr(13) & Chr(10) & "Content-Type: ") - 2
  iFn = Left(iStr, iPos3)
  If iFn <> "" Then
   iRe.AddNew
   ire("path")=left(iFn,instrrev(iFn,"\"))
   iRe("fname") = mid(iFn,instrrev(iFn,"\")+1)
   iRe("type") = Mid(iStr, iPos3 + 18)
   iRe("img").AppendChunk MidB(sBin, iPos1, iPos2 - iPos1)
   iRe.Update
  End If
End If

sBin = MidB(sBin, iPos2 + iLen + 34)
iPos1 = InStrB(sBin, iCrlf2) - 1
Wend
iRe.close
set iRe=Nothing
%>

'==================================================================
'
'  下载数据的ASP页: zj_down.asp
'
'==================================================================
<%
Response.Buffer=true
Response.Buffer=true
Response.Clear

iConcStr = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False" & _
";Data Source=" & server.mappath("zj.mdb")
set iRe=server.createobject("adodb.recordset")
iSql="tb_img"
iRe.open iSql,iconcstr,1,1
Response.ContentType=ire("type")
Response.BinaryWrite iRe("img")

iRe.close
set iRe=Nothing
%>


文章作者:未知  更新日期:2005-10-09
〖文章浏览:〗〖发送文章〗〖打印文章
〖文章阅读说明〗
·本站大部分文章转载于网络,如有侵权请留言告知,本站即做删除处理。
·本站法律法规类文章转载自[中国政府网(www.org.cn)],相关法律法规如有修订,请浏览[中国政府网]网站。
·本站转载的文章,不为其有效性,实效性,安全性,可用性等做保证。
·如果有什么问题,或者意见建议,请联系[网站管理员]。