Questions about HTML form upload file

Source: Internet
Author: User

First of all, you can test the following piece of code

    <formID= "Form1"runat= "Server">        <inputtype= "File"name= "TTT" />        <inputtype= "Submit"value= "Tap" />    </form>

And then in the background

  var files= request.files;

You'll find there's nothing in files,

Why, the original is the form did not upload file, because a property in mischief Enctype

Because the form has a property Enctype property, enctype specifies how the form data should be encoded before being sent to the server.

By default, the form data is encoded as "application/x-www-form-urlencoded". That is, all characters are encoded before being sent to the server (spaces are converted to "+" plus signs, and special symbols are converted to ASCII HEX values).

value Description
application/x-www-form-urlencoded Encode all characters before sending (default)
Multipart/form-data

Character encoding is not.

You must use this value when you use a form that contains a file upload control.

Text/plain Spaces are converted to "+" plus signs, but special characters are not encoded.

From the above table enctype the value can be seen, the default will encode all characters, when there are files uploaded directly discarded.

It's time to replace

    <formID= "Form1"runat= "Server"enctype= "Multipart/form-data">        <inputtype= "File"name= "TTT" />        <inputtype= "Submit"value= "Tap" />    </form>

Can. Note that input file must have the name attribute, or it will not be uploaded.

Form uploading files for HTML

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.