html代码:

 <!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head> <body>
<form action="http://127.0.0.1/dopost" enctype="multipart/form-data" method="POST">
姓名:<input type="text" name="name"> 性别:
<input type="radio" name="gender" value="男">男<input type="radio" name="gender" value="女">女 年龄:
<input type="number" name="age"> 图片:
<input type="file" name="img">
<input type="submit" value="提交">
</form>
</body> </html>

js代码

 let http = require('http');
let formidable = require('formidable');
let util = require('util'); //创建服务器
let server = http.createServer(function (req, res) {
//如果你的访问地址是这个,并且请求类型是post
if (req.url == '/dopost' && req.method.toLowerCase() == 'post') {
let form = new formidable.IncomingForm();
//设置文件上传存放地址
form.uploadDir = './uploads';
//执行里面的回调函数的时候,表单已经全部接收完毕了。
form.parse(req, function (err, fields, files) {
if (err) throw err;
console.log('上传文件路径:',files.img.path,'上传文件名:',files.img.name);
// console.log(util.inspect({ fields: fields, files: files }));
//所有的文本域、单选框,都在fields存放;
//所有的文件域,files
res.writeHead(200, { 'content-type': 'text/plain' }); res.end('success!~~~');
});
}
}); server.listen(80, '127.0.0.1');

最新文章

  1. Swift 2.0 异常处理
  2. 黑马程序员_ Objective-c 之Foundation笔记(二)
  3. java第6次作业
  4. cocos2d-x内存管理(见解)
  5. 关于logcat日志
  6. FusionCharts或其它flash的div图层总是浮在最上层的问题
  7. 开启Mysql远程访问的所有方法
  8. SGU 197.Nice Patterns Strike Back
  9. EJB系列 - 会话Bean基础知识
  10. kylin客户端(python编写)不能按照预期的segment进行rebuild
  11. Java获取当前的年月
  12. SpringBoot 分布式session
  13. 安装python软件找不到setuptools的解决方案
  14. [Postman]响应(7)
  15. Image.fromarray的用法
  16. Linux useful commands
  17. bzoj千题计划303:bzoj4827: [Hnoi2017]礼物
  18. spring cloud:config-server中@RefreshScope的&quot;陷阱&quot;
  19. 1.Python爬虫入门一之综述
  20. C++几个重要关键字(包含借鉴其他博主的东西)

热门文章

  1. 浅谈android Socket 通信及自建ServerSocket服务端常见问题
  2. C/C++ 运算符 &amp; | 运算
  3. SCP 命令(自己总结)
  4. 用户空间缺页异常pte_handle_fault()分析--(下)--写时复制【转】
  5. 8.OpenStack网络组件
  6. ASP.NET webFrom
  7. HDU 3466 Proud Merchants【贪心 + 01背包】
  8. 牛客网暑期ACM多校训练营(第一场) - J Different Integers(线段数组or莫队)
  9. bzoj 2843: 极地旅行社
  10. Android Developer -- Bluetooth篇 概述