The pure ASP code realizes the picture and the text synchronously uploads

Source: Internet
Author: User
Tags sql access database
Upload | Upload on the internet to see an article, modified and combined with XML, to achieve picture text synchronization upload!
Total 3 files: upload.htm,uploadtext.asp,uploadimg.asp

Create an Access database called Text.mdb, the table called Imgtable
The field has text1,img two, and an incremented ID field.
The code is as follows:

Upload.htm

<title> picture text sync upload </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>

<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>


Showpicture.asp:

<%@ Language=vbscript%>
<%
Set conn = Server. CreateObject ("Adodb.connection")
DBPath = Server. MapPath ("Test.mdb")
Conn. Open "Driver={microsoft Access driver (*.mdb)};d bq=" & 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 ' Get data
FormData = Request.BinaryRead (formsize)

function Imageup (formsize,formdata) ' functions are to intercept the image part of the
Part
Bncrlf = CHRB & ChrB (10) ' After the function is made. You can use it at your own discretion later.

Divider = LeftB (FORMDATA,INSTRB (FORMDATA,BNCRLF)-1)
Datastart = INSTRB (FORMDATA,BNCRLF&AMP;BNCRLF) +4
Dataend = INSTRB (datastart+1,formdata,divider)-datastart
Imageup = MidB (formdata,datastart,dataend)
End Function

Image = Imageup (Formsize,formdata) ' Here is the picture part.

Set rs = server. CreateObject ("Adodb.recordset")
strconn = "Driver={microsoft Access Driver (*.mdb)};d bq=" & 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) ' Here is the display image. Said
Success!
%>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.