The simplest way to sync a database without component pictures and text

Source: Internet
Author: User
Tags file upload mdb database
Data | database | No component no component pictures and text synchronized to the database in the simplest way
Dynamic Education Network Release date: 2001-7-17 words: 4798

One: Preface

First of all, did not expect the upload of pictures and text will cause so much attention. After posting a post (id=435906), a lot of people wrote that they couldn't understand. Or
is still not achievable. I'm going to use a completely simple technique. Complete the process without component text and picture upload database. I hope it helps all of you to be suspicious.
asked the Netizen.

Two: Preparation work

By convention, I'll tell you about my test environment first.
System: Win98SE + PWS + ASP
Programming Environment: Visual InterDev 6.0
Database: Access2000 (because the most users ask is the Access2000 problem.) )
Build a library: access2000, first build a Test.mdb database. There are four specific fields.
ID | Text1 | Text2 | Img
AutoNumber text text OLE object ' if it is SQL Server Select (image can)

Three: Are you ready, GO!!!

3-1. Build Upload form:
As we know, images and text are two different standard files (binary, streaming text) and if you want to submit the same form, (file format submission)
When we acquire it, we cannot use the original method Request.Form and must use Equest.totalbytes to obtain all the submissions. But in this case, the files in both formats
It's hard to mix together. My last Post has told you to use the binary method to separate the data. But it's very troublesome to use many binary letters.
Number, so many netizens wrote to ask me if there is a simpler way, OK. I can tell you that there are! and ensure that the following methods are guaranteed to be a learning. (Such side
The law is very alternative but the great man said White cat, Black Cat. The internet is a good cat! )

Upload.asp (Specific code below)

<% @ language=vbscript%>
<meta name= "Vi60_defaultclientscript" content= "VBScript" >
<title> File Upload </title>
<script id= "Clienteventhandlersvbs" language= "VBScript" >
<!--
Sub Form2_onsubmit//** Here is the key when Form2 in the process of submitting a live Form1 submission
Form1.submit//** So we've used two forms here, but only one submission is OK.
End Sub
-->
</script>
<body>

<form name= "Form1" enctype= "Multipart/form-data" action= "upimage.asp" method= "POST" target= "_blank" >
Please choose a upload: <br>
<input name= "Picture" type= "FILE" > <br>
</form>

<form name= "Form2" action= "uptext.asp" method= "POST" >
<input type= "text" name= "Text1" ><br>
<input type= "text" name= "Text2" ><br>
<input type= "Submit" value= "submitted" >
</form>

</body>

3-2 soldiers divide two ways to process the data.
First, the text is simple.

Uptext.asp (code below)

<% @ language=vbscript%>
<%
strconn= "Driver={microsoft Access Driver (*.mdb)};d bq=" &server. MapPath ("Test.mdb")

Text1=request.form ("Text1")
Text2=request.form ("Text2")
Response.Write Text1
Response.Write Text2

Set Rs=server.createobject ("Adodb.recordset")
Sql= "SELECT top 1 * imgtable ORDER BY ID DESC" ' This means selecting the last ID, which has just been altered
Rs. Open sql,strconn,1,3 ' is the two text field of the image you uploaded.

RS ("Text1") =text1 ' note that here is the change is not added, so no AddNew.
RS ("Text2") =text2
Rs. Update
Rs. Close
%>
Then, to process the image.
Upimage.asp (Specific code below)

<%
Formsize = Request.TotalBytes ' Get data
FormData = Request.BinaryRead (formsize)

function Imageup (formsize,formdata) ' functions are to intercept the part of the image.
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) ' This is the image part.

Set Rs=server. CreateObject ("Adodb.recordset")
strconn= "Driver={microsoft Access Driver (*.mdb)};d bq=" &server. MapPath ("Test.mdb")
Sql= "SELECT * from Imgtable"
Rs. Open sql,strconn,1,3

Rs. AddNew ' because form two was submitted in the process of single submission of the form.
RS ("img"). AppendChunk Image ' So here is added.
Rs. Update
Rs. Close


Response.contenttype= "Image/gif"
Response.BinaryWrite imageup (formsize,formdata) ' Here is the display image. Show Success!

%>

Ah,!?!? That's easy!

Four: "Show, I want to display with the page"
Finally finished the text synchronization submission. (Is it really synchronized?) Isn't it? Is it? Alas, we are just trying to solve the problem. Why take it seriously? No
Is that right? )
Now we have to show him the same page. In fact, this is the same idea. We also use two pages to complete.

Homepage: show.asp

<%@ Language=vbscript%>
<%
strconn= "Driver={microsoft Access Driver (*.mdb)};d bq=" &server. MapPath ("Test.mdb")

Set Rs=server.createobject ("Adodb.recordset")
Sql= "SELECT top 1 * imgtable ORDER by ID DESC"
Rs. Open sql,strconn,1,3
%>
<body>
Here is your upload material. <br>
Text One: <% Response.Write rs ("Text1")%><br>
Text Two: <% Response.Write rs ("Text2")%><br>

Your image:
> ' note here, that's the key. He can implement web images and text



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.