另一方面, multipart/form-data 导致了非常不同的表现形式 . 我不需要't remember the exact details, but each input field in your form can have a distinct MIME type and encoding. This means your browser can easily send binary files to a site, along with form data. However, the general structure of the request creates a relatively large overhead, so you should use it only when it'(即你想发送文件时) .
4 回答
添加属性enctype = "multipart/form-data"不会阻止表单接受来自其他输入类型(如文本,复选框或无线电)的数据 . 您可以使用单个表单提交所有数据 .
你可以将属性添加到
form
和里面的字段,这将工作!具有文件上载的表单也可以使用
enctype="multipart/form-data"
发布其他输入字段 .enctype
属性通过MIME类型指定表单数据在请求中的编码方式 . 我知道的两个有效的enctype是application/x-www-form-urlencoded
和multipart/form-data
.在引擎盖下,当你指定没有类型时,你会得到
application/x-www-form-urlencoded
. 这表明在发送请求时,您的浏览器将对表单数据进行编码,就像将其作为GET参数发送一样:请求正文看起来像foo=bar&bar=baz&frob=this%20has%20four%20words
. 虽然完全适用于文本字段,但这种表示对于文件传输来说非常尴尬,特别是对于二进制文件而言,其大小可能会增加三倍 . 为了避免发生这种情况,不可能使用application/x-www-form-urlencoded
来发送文件 .另一方面,
multipart/form-data
导致了非常不同的表现形式 . 我不需要't remember the exact details, but each input field in your form can have a distinct MIME type and encoding. This means your browser can easily send binary files to a site, along with form data. However, the general structure of the request creates a relatively large overhead, so you should use it only when it'(即你想发送文件时) .所以,是的,设置
enctype="mutlipart/form-data"
仍然会让你有常规字段 . 它们只是代表另一种方式,但这对你来说是完全透明的 .