纯asp代码实现图片和文本同步上传

发表于:2007-06-30来源:作者:点击数: 标签:
在网上看到一篇文章,经过修改并结合xml,实现图片文本同步上传! 共3文件:upload.htm,uploadtext.asp,uploadimg.asp 建立一access 数据库 ,叫text.mdb,表叫做imgtable 字段有text1,img两个,还有一个递增的id字段. 代码如下: upload.htm html head title图片文本
在网上看到一篇文章,经过修改并结合xml,实现图片文本同步上传!
共3文件:upload.htm,uploadtext.asp,uploadimg.asp

建立一aclearcase/" target="_blank" >ccess数据库,叫text.mdb,表叫做imgtable
字段有text1,img两个,还有一个递增的id字段.
代码如下:

upload.htm

<html>
<head>
<title>图片文本同步上传</title>
<meta name = "dongbao" content = "text/html;charset=gb2312" http-e
quiv = "Content-Type">
<script language = "javascript">
<!--hide me
function upload()
{
var xmlhttp = new ActiveXObject("Microsoft.XmlHttp");
var textcontent = "<textcontent><name>" + document.formtext.name.va
lue + "</name></textcontent>";
xmlhttp.Open("POST","uploadtext.asp",false);
xmlhttp.Send(textcontent);
return true;
}
//show me-->
</script>
</head>

<body>
<form action = "uploadimg.asp" enctype = "multipart/form-data" method
= "post" onsubmit = "return upload();">
<input name = "picture" type = "file"/>
<input type = "submit"/>
</form>
<form name = "formtext">
<input name = "name"/>
</form>
</body>
</html>


showpicture.asp:

<%@ Language=VBScript %>
<%
set conn = server.CreateObject ("adodb.connection")
dbpath = server.MapPath("test.mdb")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & dbpath

set xmldom = server.CreateObject("Microsoft.XmlDom")
xmldom.load(request)
name = xmldom.selectsinglenode("//name").text

sql = "insert into imgtable ( text1 ) values ( ‘’" & name & "‘’ )"
conn.Execute sql
%>

uploadimg.asp:

<%@ Language = VBScript %>
<%
FormSize = Request.TotalBytes ‘’得到数据
FormData = Request.BinaryRead( FormSize )

function ImageUp(formsize,formdata) ‘’这个函数的功能是截取其中的图像部
分。
bncrlf = chrb(13) & chrb(10) ‘’做成函数后。以后你可以自己随意使用了。

divider = leftb(formdata,instrb(formdata,bncrlf)-1)
datastart = instrb(formdata,bncrlf&bncrlf)+4
dataend = instrb(datastart+1,formdata,divider)-datastart
imageup = midb(formdata,datastart,dataend)
end function

Image = ImageUp (FormSize,Formdata) ‘’这里就是图像部分了。

set rs = server.CreateObject("adodb.recordset")
strconn = "driver={microsoft access driver (*.mdb)};dbq=" & server.M
apPath("test.mdb")
sql = "SELECT * FROM imgtable order by id desc"
rs.Open sql,strconn,1,3

rs("img").appendchunk Image
rs.Update
rs.Close

response.contenttype = "image/gif"
response.binarywrite imageup(formsize,formdata) ‘’这里是显示图像。表示
成功!
%>

原文转自:http://www.ltesting.net