The easiest way to store with text synchronization into the database

zhaozj2021-02-11  180

The easiest way to send into the database without component images Synchronize Database Database Date: 2001-7-17 Word Count: 4798

I. Introduction

First of all, there is no attention to the image and the text of the text will cause such a big attention. The last post (ID = 435906) After posted, many people believe that they don't understand. Or still don't be implemented. I will use a completely simple technique. Complete component-free text and upload all procedures for the database. I hope to help all netizens who have questions about this.

2: Preparation

According to the practice, I will tell you in my test environment first. System: WIN98SE PWS ASP programming environment: Visual InterDev 6.0 Database: Access2000 (because netizens ask the most of the Access2000 problem.) Built a library: Access2000, first build a Test.mdb database. There are four fields. ID | text1 | text2 | IMG Auto Number Text Text OLE Object 'If it is SQL Server, select (Image)

Three: Are you ready, Go !!!

3-1. We know that the image and text are two different types of files (binary, streaming text) and if we want to submit it, (File format submit), we can't use the original Methods Request.form must have all submission information with Equest.TotalBytes. But at this time, the two formats of formats are mixed together. My last post has told everyone to separate these materials with a binary approach. But very troublesome, you have to use many binary functions, so many netizens will ask me if there is a simpler method, good. I can tell everyone, there is! And to ensure that the following methods ensure that you will learn. (This method is very different, but the great man said the white cat, black cat. It is a good cat!)

Upload.asp (specific code is as follows)

<% @ Language = vbscript%> File Upload </ title> <script ID = "clientEventHandlersVBS" LANGUAGE = "vbscript"> < ! - SUB FORM2_ONSUBMIT // ** Here is the key. When Form2 is submitted during submission, the form of Form1 is submitted for form1.submit // **, so we use two forms here, but only one submission can be . End Sub -> </ script> </ head> <body></p> <p><form name = "form1" enctype = "multipart / form-data" action = "upimage.asp" method = "post" target = "_ blank"> please choose a picture to upload: <br> <input name = "Picture "Type =" file "> <br> </ form></p> <p><form name = "form2" action = "upText.asp" method = "post"> <input type = "text" name = "text1"> <br> <input type = "text" name = "text2"> <TEXT2> < BR> <input type = "submit" value = "Submit"> </ form> </ body> </ html></p> <p>3-2 soldiers to deal with data. First, the text is simple.</p> <p>Uptext.asp (code as follows)</p> <p><% @Language = VBScript%> <% strconn = "driver = {Microsoft Access Driver (* .mdb)}; dbq =" & Server.mappath ("test.mdb")</p> <p>Text1 = Request.form ("text1") text2 = request.form ("text2") response.write text1Response.write text2</p> <p>SET RS = Server.createObject ("AdoDb.Recordset") SQL = "SELECT TOP 1 * from imgtable order by id desc" 'Here is the last ID, both just change RS.Open SQL, STRCONN, 1, 3 'is the two text fields of the images you uploaded.</p> <p>RS ("Text1") = text1 'Note, here is the change is not added, so don't use AddNew. RS ("Text2") = text2rs.Updaters.close%> Next, the image is processed. Upimage.asp (specific code is as follows)</p> <p><% Formsize = request.totalbytes' Get Data Formdata = Request.binaryRead (Formsize)</p> <p>Function imageUp (Formsize, FormData) 'The function of this function is to intercept the image portion therein. Bncrlf = chrb (13) & chrb (10) 'is made after making functions. In the future, you can use it at it. divider = leftb (formdata, instrb (formdata, bncrlf) -1) datastart = instrb (formdata, bncrlf & bncrlf) 4dataend = instrb (datastart 1, formdata, divider) -datastartimageup = midb (formdata, datastart, dataend) end function</p> <p>Image = Imageup (Formsize, Formdata) 'This is the image section.</p> <p>SET RS = Server.createObject ("AdoDb.Recordset") StrConn = "Driver = {Microsoft Access Driver (* .mdb)}; dbq =" & Server.MAppath ("test.mdb") SQL = "Select * from imgtable" RS.Open SQL, STRCONN, 1, 3</p> <p>Rs.addnew 'Submitted by the form of forms two submitted in the form of a single submission. RS ("img"). Appendchunk image 'So this is added. Rs.Updaters.closeSponse.contentType = "image / gif" response.binaryWrite Imageup (Formsize, FormData) 'Here is a display image. Successful!</p> <p>%></p> <p>what? ! ? ! It turns out so simple!</p> <p>Four: "Show, I want to display the same page" finally completed the graphic synchronization submission. (Really synchronized? Isn't it? Yes? Hey, we are just in order to solve the problem. Why bother is true? Isn't it?) Now we have to display the same page. In fact, this is the same idea. We also use two pages to complete.</p> <p>Main page: show.asp</p> <p><% @Language = VBScript%> <% strconn = "driver = {Microsoft Access Driver (* .mdb)}; dbq =" & Server.mappath ("test.mdb")</p> <p>SET RS = Server.createObject ("AdoDb.Recordset") SQL = "SELECT TOP 1 * from imgtable order by id desc" rsopen sql, strconn, 1, 3%> <html> <body> The following is your upload data. <br> Text 1: <% Response.write RS ("Text1")%> <br> Text 2: <% Response.write RS ("Text2")%> <br></p> <p>Your image: <img src = showimg.asp? Id = <% = rs ("ID")% >> 'Note that this is the key. He can achieve web image and text </ body> 'coexist. </ html></p> <p>Behind: Showimg.asp (said he is a behind-the-scenes page, because he lurks in the main page. Look is the same as a page)</p> <p><% @ Language = vbscript%> <% strconn = "driver = {Microsoft Access Driver (* .mdb)}; dbq =" & server.mappath ("test.mdb") ID = request ("id") set = Server.createObject ("AdoDb.Recordset") SQL = "Select * from imgtable where id =" & idrs.open sql, strconn, 1, 3Response.contettype = "image / gif" response.binaryWrite RS ("IMG")%></p> <p>(Full text: I hope this article can help those users who are eager to solve this kind of question.)</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-5008.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="5008" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.045</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'IYzwCvv0GPqtQt8Afc4hNJOCmRN1lo61D8i6S7ceSrR8mEZVe2YXh0i5YvEukEX41eOItkY_2B6lWbxeDARKe5rg_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>