純asp代碼實現圖片和文本同步上傳

來源:互聯網
上載者:User
上傳|上傳 在網上看到一篇文章,經過修改並結合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) '這裡是顯示映像。表示
成功!
%>



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.