Using ASP to improve document upload control (turn)

Source: Internet
Author: User
Tags date1 dsn iis rfc servervariables
Control using ASP to improve document upload controls



With the development of the Internet, the way people publish and access information has changed radically, more and more people begin to use the network as the most important way to publish and get information, at the same time, the technology that can publish and make information sharing is more and more. Although these technologies have brought great convenience to developers, some of these technologies are still flawed for a variety of reasons. Therefore, developers in the selection and use of various technologies, we must recognize the advantages and limitations of these technologies, to learn from each other to design a full-featured program.
Ask a question
The author has developed a web-based document resource sharing information Web site in the construction of enterprise intranet Information Network project. This web site requires that uploaded documents be automatically connected to the corresponding columns according to the document's category in the home page by document headings. In view of this demand, the author uses the document upload control of IIS Posting Acceptor components, combined with database and web technology, has developed a high degree of automation document automatic Web Publishing system and Automatic document Web page generation system. In the process of developing this system, the author discovers that there are some problems in the use of upload Control Cpshost.dll under IIS. For example, in order to complete the upload, the author developed two programs: program One (upload.asp) to provide web-based information document upload input interface; program two (wd_writer.asp) record the information of the program into the database. The relevant code is as follows:
Program One (upload.asp):
......
' Provides a client interface for document uploads
<form enctype= "Multipart/form-data" action= "http://<%= request.servervariables
("SERVER_NAME")%>/scripts/cpshost.dll? Publish?wd_writer.asp "method=" POST ">
<p> Document topics: <input type= "text" name= "subject" ><br>
Author: <input name= "Author" type= "text" ><br>
Publish time: <input name= "Date1" type= "text" ><br>
Upload Document name (click Browse button to choose): <input type= "file" name= "filename" >
Destination URL: <input type= "hidden" name= "TargetUrl"
Value= "http://<%= request.servervariables (" SERVER_NAME ")%>/users/wdls" >
<input type= "Submit" value= "release OK" > </p>
</form>
......
Program II (wd_writer.asp):
<% ' Open Database
Set MyData = Server.CreateObject
("ADODB.") Connection ")
MyData. Open "DSN=XCZH; Uid=sa; pwd=; "
' Take the contents out of the form
Date1=request.form ("Date1") ' Take time
' Take document theme
Subject=request.form ("Subject")
' Fetch the author
Author=request.form ("Subject")
' Take document file name
Filename=request.form ("filename")
' Take the physical address that the document holds in the Web server
Targeturl=request.form ("filename")
' Write database
sqlstr= INSERT INTO WDLSB values ("& SN &", ' "& Subject & &", ' "& Date1 &", ' "& FileName &", "" & TargetUrl & "," "& A Uthor & "')"
Mydata.execute (SQLSTR)
%>
The syntax and logical structure of the above program are correct, but there is a problem when it is used. When the Chinese characters are filled out in the subject, Author and filename fields of the program one, the form field values taken out by request in program two are garbled, that is, the field value can not be retrieved correctly from the form. At this point, the form carries out a POST request service when the domain value's encapsulation mode (enctype) is "Multipart/form-data", that is, RFC 1867. So the author of the program as a POST request Service encapsulation mode modified to "text", but there are "unable to upload documents" error. The author analyzes that the document upload control Cpshost.dll can only be uploaded between the browser and the server under the Multipart/form-data encapsulation mode of the form (RFC 1867 format).
Solve the problem
The author adopts the method of changing the operation flow to solve the above problems. First, the user fills out the form (Cheng upload.asp) and submits it to program IV (wd_read.asp) for preprocessing. In program IV, use the Session object to temporarily save the input values of form fields such as subject, author, date1, filename, targeturl, etc. Output a confirmation page to the user, and the user confirms the form again. Then, set the encapsulation mode of the form to "Multipart/form-data" and upload the operation. Finally, the program is called by Cpshost.dll Five (wd_writer.asp). The domain values stored in the session of the built-in object are removed by program five, and the database operation and operation confirmation are performed. If there is an unpredictable error in program four, the document upload fails and the program five is not invoked, thus maintaining the integrity of the database. The relevant code is as follows:
Cheng (upload.asp):
<form action= "http://<%= Request.
ServerVariables ("SERVER_NAME") >/wd_read.asp "method=" Post >
<p> Document topics: <input type= "text" name= "subject" ><br>
Author: <input name= "Author" type= "text" ><br>
Publish time: <input name= "Date1" type= "text" ><br>
Upload Document name (click Browse button to choose): <input type= "file" name= "filename" >
Destination URL: <input type= "hidden name=" TargetUrl "value=" http://<%= Request
. ServerVariables ("SERVER_NAME")%>/users/<%=request.servervariables ("Logon_User")%> "size=" ><br >
<input type= "Submit" value= "release OK" > </p>
</form>
Program IV (WD-READ.ASP):
<% ' Remove form field values from program three and save in session
Session ("Subject") =request.form ("subject")
Session ("Date1") =request.form ("Date1")
Session ("Author") =request.form ("author")
Session ("filename") =request.form ("filename")
Session ("TargetUrl") =request.form ("TargetUrl")
%>
......
<form enctype= "Multipart/form-data" action=
"Http://<%= Request.ServerVariables
("SERVER_NAME")%>/scripts/cpshost.dll? Publish?wd_writer.asp "method=" POST ">
Upload filename (click browse button to choose): <input type= "file" name= "filename" value= "<%=session (" filename ")%>" >
<input type= "hidden" name= "TargetUrl"
Value= "http://<%= request.servervariables (" SERVER_NAME ")%>/users/wdls" >
<input type= "Submit" value= "release OK" > </p>
</form>
Program V (wd_writer.asp):
<% ' Open Database
Set MyData = Server.CreateObject
("ADODB.") Connection ")
MyData. Open "DSN=XCZH; Uid=sa; pwd=; "
' Take the values of the form fields
Date1=session ("Date1") ' Take time
Subject=session ("subject") ' Take document theme
Author=session ("subject") ' Fetch author
Filename=session ("filename") ' Take the document name
' Take the physical address that the document holds in the Web server
Targeturl= session ("TargetUrl")
' Write the database, save the document record
sqlstr= INSERT INTO WDLSB values ("& SN &", ' "& Subject & &", ' "& Date1 &", ' "& filename &", ' "& TargetUrl &", "" & AUT Hor & "')"
Mydata.execute (SQLSTR)
%&



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.