• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

无组件实现文件上传/下载

asp 搞代码 4年前 (2022-01-03) 31次浏览 已收录 0个评论
‘ 用ASP实现无组件上传/下载文件 
‘ 
‘ 功能简介  
‘ 将上传的文件数据保存到数据库中,可以处理表单中的多个上传文件的情况 
‘ 适用于各种数据库,使用ADO的方法连接数据库 
‘ 本示例中使用的是ACCESS数据库:zj.mdb 
‘ 表:tb_img(id int(自增列),path text(255) 保存上传文件的目录 
‘ ,fname text(250) 保存上传的文件名,type test(250) 保存上传文件的类型 
‘ ,img ole对象 保存上传的文件内容 
‘ 
‘  
‘================================================================== 

‘================================================================== 
‘ 
‘ 上传文件的HTML页: zj_up.htm 
‘ 
‘================================================================== 

代码如下:
 
 
文件上传保存到数据库中 
 
 
 

 
 
 

 
 
 
 

‘================================================================== 
‘ 
‘ 上传文件保存到数据库的ASP来源gaodai#ma#com搞*!代#%^码网页: 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, “; filename=”””) + 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.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 
%>

以上就是无组件实现文件上传/下载的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:无组件实现文件上传/下载
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址