Analysis and Research on File Upload Method in Web Page

xiaoxiao2021-03-06  41

Here's this article is what I have learned from the Internet. Keep the author's name. -------------------------------------------------- ----------------------------- Analysis and Research on File Upload Method in Website Ning Denlu Cai Jie Jiang Dafu (Dandong Department of Computer Science and Technology, Vocational and Technical College, Dandong 118003, China) Nnffll@163.net

Summary: In a browser / server-based application environment, upload a variety of files in your browser have always been one of the difficulties that plague user file management applications. There are three mechanisms in the Upload file in HTTP: RFC1867, PUT and WebDAV. Common implementation methods are a new type introduced in RFC1867: File and ADO Stream objects. This paper discusses the above upload method and implementation principles, and gives a specific solution. Keywords: ASP component File object

Currently, the application based on the browser / server mode is popular. When the user needs to transfer files to the server, one of the common methods is to run the FTP server and set each user's FTP default directory to the user's web home directory, so that the user can run the FTP client and upload files to specified Web directory. This requires users to know how to use the FTP client. Therefore, this solution is only possible to familiarize with FTP and experienced users. If we can integrate file upload features with Web, users can use web browsers to complete upload tasks, which will be very convenient for them. However, since the file system object can only transfer the limitations of the text file, the biggest problem with the ASP is the file upload problem. The following describes how to upload the file in a web page based on HTTP protocol. One. Three mechanisms uploaded by HTTP have three mechanisms by HTTP: RFC1867, PUT and WebDAV. PUT is introduced in HTTP 1.1 into a new HTTP verb. When the web server receives an HTTP PUT and an object name, it will verify the user, receive the contents of the HTTP stream, and store it directly into the web server. Since this may cause damage to a Web site, and will lose HTTP's largest advantage: server programmability. In the case of PUT, the server handles the request: no space allows the CGI or ASP application to intervene. The only way to capture the PUT for your application is to operate at a low-level operation, the ISAPI filter layer. PUT's application is limited due to corresponding reasons. WebDAV allows distributed certification and translation of Web content. It introduces several new HTTP verbs that allow for Upload, lock / unlock, register / test the web content via HTTP. "Save to Web" in Office 2000 is implemented by WebDAV. If everything you are interested is uploaded, WebDAV is very good, it solves a lot of problems. However, if you need to upload files in your web application, WebDAV is useless to you. Like HTTP PUT, those WebDAV verbs are interpreted by the server, not a web application. You need to work in the ISAPI filter layer to access these verbs of WebDAV and explain the content in your application. RFC1867 (http://www.ietf.org/rfc/rfc1867.txt) was eventually accepted by W3C in HTML3.2, as a recommendation standard. It is a very simple but powerful idea: define a new type in the form field. and in the form itself adds different coding schemes, no longer uses typical:

This encoding scheme is efficient than the default" Application / X-URL-Encoded "form encoding scheme when transmitting large amounts of data. Much higher. The URL encoding is only a limited character set. Use any characters that exceed the character set, must be replaced with '% NN', where NN represents the corresponding 2 hexadecimal numbers. For example, even the ordinary space character is replaced with '% 20'.

The RFC1867 uses multiple MIME encodings, just like it is often seen in the E-mail message, not encoding a large amount of data, but only adds little but simple but practical heads around the data. The main browser manufacturers have adopted the recommendation "Browse ..." button, and users can easily use the local "Open File ..." dialog to select the file you want to upload. RFC1867 still leaves the flexible method uploaded by most files to your web application. PUT is used very limited. WebDAV is very useful for the author of content, such as FrontPage users, but Web developers who want to join files in a web application are rarely used. Therefore, RFC1867 is the best way to join file uploads in a web application. In practical applications, Microsoft offers Posting Acceptor. ASP does not understand the "Multipart / Form-Data" coding scheme. Instead, Microsoft provides Posting Acceptor, Posting Acceptor is an ISAPI application that accepts Repost to an ASP page after the upload is completed. SA-Fileup of Software Artisans is one of the earliest commercial Active Server components. Several improvements, now exists as a purely ASP component. There are also similar components to be used in China. Based on ASP-based file upload implementation Principle Analysis Basic Principle is: BINARYREAD method using the ADO Stream object, read all data in the Form, from the required file data, and stores in binary files. Below is an example of upload file page (UPLoad.htm): program used file objects, so The original data read by binaryread method in UPLOAD.ASP is not only the data of the selected file itself, but also includes the path, type, submission page of the file on the user's hard disk, so that we will The specific content of the file is required. According to the analysis, the header information of the data and the data of the data is two pairs of carriage return, and the tail also has separated information, we can use the following method to obtain file data.

Dim FormData.FormSize, DataStart, CLStr, DivStrFormSize = Request.TotalBytesFormData = Request.BinaryRead (FormSize) CLStr = ChrB (13) & ChrB (10) DataStart = InStrB (FormData.CLStr & CLStr) 4'4 are two pairs of carriage return linefeed Length divstr = Leftb (FormData, INSTRB (FormData, CLSTR) -1) DataSize = INSTRB (Datastart 1, Formdata, Divstr) -datastart-2formData = MIDB (FormData, Datast, DataSize) Formdata is the content of the file. The intermediate can be processed according to the needs. The final job is to save the file. There are two ways to save: one is to use the binary operation method in the VB or VC program, add the appropriate type library in the project, and finally compile into a DLL file, and then register the DLL file when used. . File storage procedure is as follows: Public Function SaveFile (Pathname As String) As String Dim objContext As ObjectContext Dim objRequest As Request Set objContext = GetObjectContext () Set objRequest = objContext ( "Request") 'the following piece of code is stored in the file For operation Dim FormData () As Byte, cLStr, DivStr Dim DataStart As Long, DataSize As Long DataSize = objRequest.TotalBytes Redim FormData (DataSize-1) FormData = objRequest.BinaryRead (DataSize) cLStr = ChrB (13) & ChrB (10 ) DataStart = InStrB (FormData, cLStr & cLStr) 4 DivStr = LeftB (FormData, InStrB (FormData, cLStr) -1) DataSize = InStrB (DataStart 1, FormData, DivStr) -DataStart-2 FormData = MidB (FormData, DataStart, Datasize 'Creates a binary and writes FormData for binary as 1 Put # 1, FormData Close # 1 savefile = "ok!" End Function second method is to use the binary provided in ADO STREAM File operation methods are completed, the statement to save the file is: streamobj.savetofile (filename, 2). In this operation, we can put the relevant operations in a class file, and it is possible to include this class file directly in the ASP program when applying. For specific processing methods, please refer to the relevant introduction. three. File Upload Implementation Method Instance Implementation File Upload Accessibility Components or Unparalleled Methods.

For component classes, such as Microsoft Posting Acceptor (MPA) is a free server component released by Microsoft, which is also convenient to install this component. For Microsoft's MPA, it is possible to run its installation file. In the form of a general DLL component, we need to register. For example, to use aspcnup.dll, as long as REGSVR32 [PATH /] aspcnup.dll is executed on Window 2000, the system can use the message to use this component; for unbalanced classes, such as www.5xsoft.com Component Uploaded - UPLOAD_5XSOFT. When using, as long as the following statement is included in the handler: set upload = new upload_5xsoft 'Establish an upload object related to the properties and operation method, please Refer to the user's manual. The following is an aspcnup.dll component as an example, upload some type of file source code (UPLOAD.ASP): <% @ language = "vbscript" set fileup = server.createObject ("aspcn.upload" fileup.maxsize = 200000 fileup .Path = "d: / upfile" fileup.upload for i = 0 to fileup.count fieldname = fileup.fieldname (i) if fileup.filetype (fieldname) = "zip" or ileup.filetype (fieldname) = "rar" = "rar" The fileup.save fieldname endup = nothing%> 4. Endy language browser / server application mode is still developing quickly, and the new ASP in Microsoft. In the NET, the file uploaded file has been built, and the use is very simple and convenient. As a brand new technology, ASP. NET is not just an Simple upgrade of ASP, which is a new framework for web development, which contains many new features. ASP. NET provides more easy to write, more clearer code, using these code we will easily use and share more easily, thereby developing more more practical programs. Reference: [1] ASP.NET and VB.NET from Getting Started into Maastering ASP.NET with VB.NET [US] A.Russell Jones, Gao Chun Rong, etc., E-Industry, 2002 [2] ASP Component Development Guide (DEVELOPING ASP Components Second Edition) Shelley Power, He Jianhui, etc. China Electric Press, May 2002 [3] Network Program Design - SP Cai Cuiping, editor, North Jiaotong University Press, Tsinghua University Press, 2002 January [4] US IDG "Collection" series: Visual Basic database programming book [United States] Wayne Freeze Yin Yu and other translation Electronic Industry Press in May 2001 [5] RFC1867 http://www.ieetf.org/rfc /RFC1867.TXT E. Nebel L. Masinter

转载请注明原文地址:https://www.9cbs.com/read-53335.html

New Post(0)