php/html文件上传中的enctype属性

来源:互联网 发布:新买的mac自带解压么 编辑:程序博客网 时间:2024/05/21 05:55

先贴一个最简单的文件上传模型

<html><form method="post" action='index.php' enctype="multipart/form-data"><input type="file" name="file" id="file"><input type="submit" value="提交"></form></html><?phpif (isset($_FILES['file'])) {$dst = './test_'.$_FILES['file']['name'];move_uploaded_file($_FILES['file']['tmp_name'], $dst);}

可以看到,form中添加了enctype="multipart/form-data"属性.enctype共有三种类型:

值描述application/x-www-form-urlencoded在发送前编码所有字符(默认)multipart/form-data

不对字符编码。

在使用包含文件上传控件的表单时,必须使用该值。

text/plain空格转换为 "+" 加号,但不对特殊字符编码。






enctype属性的作用是设置表单传输的编码。通过抓包可以看到由enctype设置的MIME编码:




1 0
原创粉丝点击