这段上传图片的代码那里错了、?(显示乱码)
这段上传图片的代码那里错了、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中显示不出来图片,而是乱码???