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&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!
%>