In the form for uploading files, the <form> attribute enctype = "multipart/form-Data" must be added. Many people just remember that the upload form must be written in this way, but do not know why. So why should we add this attribute? What does it mean? What other optional values does it have?
In fact, when you do not write the enctype attribute for the form, the enctype attribute value is also added by default. The default value is enctype = "application/X-WWW-form-urlencoded ". this attribute manages the form mime encoding. There are three optional values:
① Application/X-WWW-form-urlencoded (default)
② Multipart/form-Data
③ Text/plain
① 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 tasks are the same, that is, to set the encoding of form transmission. An error may be returned if you do not write it in Ajax, but enctype = "application/X-WWW-form-urlencoded" can be left in the form of HTML, because the default HTML form is the Transfer Encoding type. ② Multipart-form-data is used to specify a special type of data transmission. It is mainly the non-text content that we upload, such as parts or mp3 files. ③ Text/plain is the meaning of plain text transmission. This encoding type should be set when sending an email; otherwise, the encoding will be messy During reception, on the Internet, we often compare text/plain with text/html. In fact, these two are very different. The former is used to transmit plain text files, and the latter is used to transmit the encoding type of HTML code, it is used only when the header file is sent. Neither ① nor ③ can be used to upload files. Only multipart/form-data can completely transmit file data.
The mime mentioned above, its full name is "Multipurpose Internet Mail Extensions" multi-function Internet Mail Extension Service. It is a multi-purpose Internet Mail Extension protocol, which was first used in the email system in 1992, but it will also be applied to browsers later. The server will tell the browser the type of multimedia data they send, and the notification means to indicate the MIME type of the multimedia data, so that the browser can know the received information which is MP3 files, which are shockwave files. The server puts the mime token into the transmitted data to tell the browser which plug-in is used to read the relevant file.
To put it simply, the MIME type is to set the type of a file with a certain extension to be opened by an application. When the file with this extension is accessed, the browser automatically opens the application with the specified application. It is used to specify custom client file names and open media files.
After the browser receives the file, it will go to the plug-in system to find out which plug-in can identify and read the received file. If the browser does not know which plug-in system to call, it may tell the user that a plug-in is missing, or directly select an existing plug-in to try to read the received file, the latter may cause a system crash. The absence of mime identifiers in the transmitted information may make it difficult to estimate the situation, because some computer systems may not have any faults, but some computers may crash.
To check whether a server correctly sets the MIME type, follow these steps:
1. Open the server webpage in the Netscape Browser
2. Go to the "View" menu and select "Page Info"
3. Click "embed" in the upper-layer framework in the pop-up window"
4. check whether the MIME type is "application/X-director" or "application/X-Shockwave-flash" in the lower-layer framework ", if the above information is used, it indicates that the server has correctly set the MIME type; if the MIME type lists text content, eight-bit data, or other forms, it indicates that the server's MIME type is not set correctly.
If the server does not correctly indicate the type of data it sends, the server administrator should correctly add relevant information. The specific operation method is very simple and quick.
Each MIME type consists of two parts. The front part is a large data type, such as audio, image, and so on. The latter part defines a specific type.
Common MIME types
Hypertext markup language text .html, .html text/html
Common text. TXT text/plain
RTF text. rtf application/RTF
GIF image. GIF image/GIF
JPEG image. jpg image/JPEG
AU audio file. Au audio/basic
MIDI music files mid,. MIDI audio/Midi, audio/X-Midi
RealAudio music file. Ra,. Ram audio/X-PN-RealAudio
MPEG file. mpg,. MPEG Video/MPEG
AVI file. AVI Video/X-msvideo
Gzip file. GZ application/X-Gzip
Tar file. Tar application/X-Tar
There is a dedicated IANA organization in the Internet to confirm the standard MIME type, but the Internet is growing too fast, and many applications cannot wait for IANA to confirm that they are using the standard MIME type. Therefore, they use methods starting with X-in the category to identify this category, such as X-gzip and X-tar. In fact, these types are widely used and have become the de facto standard. As long as the client and server acknowledge this mime type together, even if it is not a standard type, the client program can process data according to the MIME type. In web servers and browsers (including operating systems), standard and common MIME types are set by default, the server and client browser must be set for identification.