Why add a property to the form where the file is uploaded enctype

Source: Internet
Author: User
Tags html form

Why add a property to the form where the file is uploaded enctype

Upload a file in the form <form> to add attributes Enctype= "Multipart/form-data", many people just rote know upload form to write so, know it but do not know why. So why do you add this property? What does it mean? What other optional values does it have?

In fact, when you do not write the Enctype property, the Enctype property value is added by default, and the default value is Enctype= "application/x-www-form-urlencoded". This property manages the MIME encoding of the form, A total of three values are optional:

①application/x-www-form-urlencoded (default value)

②multipart/form-data

③text/plain

Where ①application/x-www-form-urlencoded is the default value, you may have seen this in Ajax: Xmlhttp.setrequestheader ("Content-type", "application/ X-www-form-urlencoded "); The two things to do is to set the encoding of the form transfer. It is possible to make an error in Ajax without writing, but the HTML form table dropdowns can not write enctype= "application/x-www-form-urlencoded" because the default HTML forms are the type of transmission encoding.

And ②multipart-form-data is used to specify the special type of transmission data, mainly we upload non-text content, compared to tablets or MP3 and so on.

③text/plain is the meaning of plain text transmission, in the sending of the message to set this type of encoding, or receive when the coding confusion, the network often compare text/plain and text/html, in fact, these two very good distinction between the former used to transfer plain text files, The latter is the encoding type that passes the HTML code, which is used only when the header file is sent. ① and ③ cannot be used to upload files, only multipart/form-data can pass the file data intact.

The above mentioned MIME, its full name is "Multipurpose Internet Mail Extensions" Multi-functional Internet Message expansion service, it is a multi-purpose Internet Mail Expansion protocol, in 1992, the earliest application of the e-mail system, But later also applied to the browser. The server will tell the browser the type of multimedia data that they send, and the notification means that it describes the MIME type of the multimedia data, allowing the browser to know what the MP3 file is, which is the shockwave file, and so on. The server puts the MIME marker in the transferred data to tell the browser which plug-in to use to read the relevant file.

Simply put, the MIME type is the type of file that is set up with an extension that is opened by an application, and the browser automatically opens with the specified application when the extension file is accessed. Many are used to specify some client-customized file names, as well as some ways to open media files.

After the browser receives the file, it will go to the plug-in system to find out which plug-in can recognize the read received file. If the browser does not know which plug-in system to call, it may tell the user that a plugin is missing, or directly select an existing plug-in to attempt to read the received file, which may cause a system crash. The lack of a MIME identity in the transmitted information can be difficult to estimate because some computer systems may not fail, but some computers may crash as a result.

The steps to check if a server is setting the MIME type correctly are:

1. Open the Server Web page in the Netscape browser

2. Go to the "View" menu and select "Page Info"

3. In the pop-up window, click "EMBED" in the upper frame.

4. In the lower frame, see if the MIME type is "Application/x-director" or "Application/x-shockwave-flash", and if this is the case, the server has set the MIME type correctly , and if the MIME type lists text content, eight-bit data, or any other form, it indicates that the MIME type of the server is not set correctly.

If the server does not correctly indicate the type of data it sends, the server administrator should add the relevant information correctly, and the method of operation is very simple and quick.

Each MIME type consists of two parts, preceded by a large category of data, such as audio audio, image image, and so on, followed by a specific category.

Common MIME Types

Hypertext Markup Language text. html,.html text/html

Plain text. txt Text/plain

RTF text. rtf Application/rtf

GIF graphics. gif image/gif

JPEG graphics. Jpeg,.jpg Image/jpeg

Au sound file. Au audio/basic

Midi Music files Mid,.midi Audio/midi,audio/x-midi

RealAudio music files. RA,. Ram Audio/x-pn-realaudio

MPEG files. Mpg,.mpeg video/mpeg

AVI file. avi Video/x-msvideo

gzip file. GZ application/x-gzip

Tar file. Tar Application/x-tar

  

The Internet has a special organization IANA to confirm the standard MIME type, but the internet is growing too fast, and many applications can't wait for the IANA to confirm that they use the MIME type as the standard type. So they use a method that begins with X in the category to identify that the category has not yet become a standard, such as X-gzip,x-tar. In fact, these types are widely used and have become the standard of fact. As long as both the client and the server recognize this MIME type, even if it is not a standard type, the client program can handle the data according to the MIME type using specific processing methods. Both the standard and common MIME types are set by default in Web servers and browsers (including operating systems), and only for uncommon MIME types, you need to set up both the server and the client browser for identification purposes.

Why add a property to the form where the file is uploaded enctype

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.