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.