File upload does not work without enctype="multipart/form-data"

The default content type of HTML form is application/x-www-form-urlencoded. The content type of the form is denoted by enctype. The enctype can only be used with POST request.

The enctype can have following three values:
1. application/x-www-form-urlencoded (default)
2. multipart/form-data
3. text/plain

Inside a HTML form the normal fields (elements) content type is set to "text/plain" where as the file type input element's content type is "application/octet-stream"

When enctype="multipart/form-data" is not used then it does not send the file type input element to the server.

But when enctype="multipart/form-data" is used then it includes file type input element along with plain text fields and send to the server for further processing.

Comments