上傳|上傳 在網上看到一篇文章,經過修改並結合xml,實現圖片文本同步上傳!
共3檔案:upload.htm,uploadtext.asp,uploadimg.asp
建立一access資料庫,叫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) '這裡是顯示映像。表示
成功!
%>