1、Form表单上传

接下来我们使用HTML标签来创建文件上传表单,以下为要注意的点:

  • form表单 method 属性必须设置为 POST 方法 ,不能使用 GET 方法。
  • form表单 enctype 属性需要设置为 multipart/form-data

  enctype 属性规定在发送到服务器之前应该如何对表单数据进行编码。默认地,表单数据会编码为 “application/x-www-form-urlencoded”。就是说,在发送到服务器之前,所有字符都会进行编码(空格转换为 “+” 加号,特殊符号转换为 ASCII HEX 值)。而当设置了该编码格式时,不能直接上传文件。因此,这里我们使用另外一种编码格式,即multipart/form-data,该编码格式不对数据进行编码,而是直接上传二进制数据,form里面的input的值以二进制的方式传过去。

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>上传文件</title>
</head>
<body>
    <form id="my_form" name="form" action="/index" method="POST"  enctype="multipart/form-data" >
        <input name="fff" id="my_file"  type="file" />
        <input type="submit" value="提交"  />
    </form>
</body>
</html>
index.html

相关文章:

  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2021-09-26
  • 2021-08-14
猜你喜欢
  • 2021-10-18
  • 2021-11-20
  • 2021-12-10
  • 2021-12-28
  • 2021-05-26
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案