| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 916 人关注过本帖
标题:这段上传图片的代码那里错了、?(显示乱码)
只看楼主 加入收藏
lijiong520
Rank: 1
等 级:新手上路
帖 子:154
专家分:0
注 册:2007-5-21
收藏
 问题点数:0 回复次数:0 
这段上传图片的代码那里错了、?(显示乱码)
这段上传图片的代码那里错了、
conn.asp

<%
dim conn
dim connstr
on error resume next
connstr="DBQ="+server.mappath("../user.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
Sub rsclose()
rs.close()
set rs=nothing
End Sub
Sub connclose()
conn.close()
set conn=nothing
End Sub
%>
---------------------------------
index.asp
<!--#include file="conn.asp"-->
<%
act = Request.Querystring("act")
if act="up" then
uploading(file)
else
%>
<form name="form1" enctype="multipart/form-data" method="post" action="index.asp?act=up">
<p>
<input type="file" name="file">
<input type="submit" name="Submit" value="上传">
</p>
</form>
<%
view()
end if
%>
<%
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

function uploading(file) '上传函数!
Response.Expires=0
set iRe=Server.CreateObject("ADODB.Recordset")
iSql="tb_img"
iRe.Open iSql,conn,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
set iRe1=Nothing
view()
%>


<form name="asdf">
<input type="text" name="ice">
</form>

<SCRIPT LANGUAGE="VBScript">
<!--
Set TheForm = Document.asdf
TheForm.ice.Value="<%=left(iFn,instrrev(iFn,"\"))%>"
-->
</SCRIPT>
<%
end function'上传函数结束!
%>

<%
function view() '查看链接函数
sql="select*from tb_img order by id desc"
set rs=Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,3
i=1
do while not rs.eof
%>
i:<a href=view.asp?id=<%=rs("id")%> target="_blank"><%=rs("fname")%></a><br>
<%
rs.movenext
loop
rs.close
set rs=nothing
end function
%>
---------------------

View.asp
<%
requestID=Request.Querystring("id")
Response.Buffer=true
Response.Clear

iConcStr = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False" & _
";Data Source=" & server.mappath("../user.mdb")
set iRe=server.createobject("adodb.recordset")
iSql="select * from tb_img where id=" & requestID
iRe.open iSql,iconcstr,1,3
do while not iRe.eof
'Response.ContentType="image/*" 这句话要不要啊,要这句代码的话,出来是“保存文件”,不要的话,是乱码
Response.BinaryWrite iRe("img")
response.write"<br>"
iRe.movenext
loop
%>

其中,View.asp中显示不出来图片,而是乱码???

文件.rar (2.82 KB) 源文件和数据库中字段说明

搜索更多相关主题的帖子: 上传图片 conn 乱码 Microsoft 
2008-03-17 17:01
快速回复:这段上传图片的代码那里错了、?(显示乱码)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.064575 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved