惊艳·ASP里的黑洞!
我用了下面的代码上传图片到SQL Server数据库asp中的数据表imges中:我分别上传了jpeg,gif图片,上传后打开数据表可以看到数据库中的img字段(image类型)被填充了,而且在页面中也列出了图片,只是图片没有显示出来,在图片的位置显示小红叉(就是最常见的那种无法显示图片时代替图片的东东),查了很多资料都是这样写代码,那么问题到底出在哪里了那????????
/////////////////////////////
(upload.htm):
<html>
<body>
<center>
<form name="mainForm" enctype="multipart/form-data"
action="process.asp" method=post>
<input type=file name=mefile><br>
<input type=submit name=ok value="OK">
</form>
</center>
</body>
</html>
//////////////////////////////////
(process.asp):
<%
response.buffer=true
formsize=request.totalbytes
formdata=request.binaryread(formsize)
bncrlf=chrB(13) & chrB(10)
divider=leftB(formdata,clng(instrb(formdata,bncrlf))-1)
datastart=instrb(formdata,bncrlf & bncrlf)+4
dataend=instrb(datastart+1,formdata,divider)-datastart
mydata=midb(formdata,datastart,dataend)
set connGraph=server.CreateObject("ADODB.connection")
connGraph.ConnectionString="driver={Microsoft Access Driver (*.mdb)};DBQ=" &
server.MapPath("images.mdb") & ";uid=;PWD=;"
connGraph.Open
set rec=server.createobject("ADODB.recordset")
rec.Open "SELECT * FROM [images] where id is null",connGraph,1,3
rec.addnew
rec("img").appendchunk mydata
rec.update
rec.close
set rec=nothing
set connGraph=nothing
%>
/////////////////////////////
showimg.asp):
<%
set connGraph=server.CreateObject("ADODB.connection")
connGraph.ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;pwd=sql;Initial Catalog=asp;Data Source=(local);"
connGraph.Open
set rec=server.createobject("ADODB.recordset")
strsql="select img from images where id=" & trim(request("id"))
rec.open strsql,connGraph,1,1
Response.ContentType = "image/*"
Response.BinaryWrite rec("img").getChunk(7500000)
rec.close
set rec=nothing
set connGraph=nothing
%>