Role of the Enctype attribute of Form labels and application example _ HTML/Xhtml _ webpage Creation

Source: Internet
Author: User
Enctype is the encoding type used by the browser when data is sent back to the server. The encoding types are as follows. The following example shows how to use Enctype in detail: specifies the encoding type used by the browser when data is sent back to the server. Used to upload images in a form.

There are three encoding types:

Application/x-www-form-urlencoded: encode all characters before sending (default ). This is the standard encoding format.
Multipart/form-data: this value is not character encoded. This value must be used when using a form containing the File Upload control.
Text/plain: the form data is encoded in plain text format, which does not contain any controls or format characters.

Example:

The Code is as follows:




In the form, enctype = "multipart/form-data" indicates the MIME encoding of the table ticket. By default, the encoding format is application/x-www-form-urlencoded and cannot be used for file upload. Only multipart/form-data can be used to completely transmit file data.

Enctype = "multipart/form-data" is used to upload binary data.

If the server needs to obtain the value of the corresponding form field through the Request object, set the enctype attribute to the value of application/x-www-form-urlencoded (default value, can not display settings ).

Why enctype = "multipart/form-data" should be set for file uploading ":

Because: After the enctype is set to the multipart/form-data value, the data is transmitted to the server in binary format without character encoding, in this case, if the request cannot directly obtain the value of the corresponding form, the stream object should be used to decode the binary data uploaded to the server to read the data.

To upload a file, you must set encotype to multipart/form-data.

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.