简单实现nodejs上传功能
诸葛苍穹 人气:0本文实例为大家分享了Android九宫格图片展示的具体代码,供大家参考,具体内容如下
npm install formidable
var formidable = require('formidable'), http = require('http'), util = require('util'); http.createServer(function(req, res) { if (req.url == '/index' && req.method.toLowerCase() == 'post') { // parse a file upload var form = new formidable.IncomingForm(); form.uploadDir = './upload'; form.parse(req, function(err, fields, files) { console.log(fields); console.log(files); }); } }).listen(3001);
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <form action="http://127.0.0.1:3001/index" method="post" enctype="multipart/form-data"> <p> 姓名:<input type="text" name="name"> </p> <p> 性别:<input type="radio" name="sex" value="男">男 <input type="radio" name="sex" value="女">女 </p> <p> 爱好:<input type="checkbox" name="hobby" value="吃饭">吃饭 <input type="checkbox" name="hobby" value="睡觉">睡觉 <input type="checkbox" name="hobby" value="游泳">游泳 </p> <p> 文件上传:<input type="file" name="images"> </p> <p> <input type="submit" value="提交"/> </p> </form> </body> </html>
加载全部内容