首页 > 代码库 > node 上传文件
node 上传文件
file.js文件
需要安装formidable 模块
var formidable = require(‘formidable‘); var http = require(‘http‘); var sys = require(‘sys‘); http.createServer(function(req, res) { if (req.url == ‘/upload‘ && req.method.toLowerCase() == ‘post‘) { // parse a file upload var form = new formidable.IncomingForm(); form.parse(req, function(err, fields, files) { res.writeHead(200, {‘content-type‘: ‘text/plain; charset=UTF-8‘}); res.write(‘received upload:\n\n‘); res.end(sys.inspect({err:err, fields: fields, files: files})); }); return; } // show a file upload form res.writeHead(200, {‘content-type‘: ‘text/html; charset=UTF-8‘}); res.end( ‘<body>‘+ ‘<form method="post" action="/upload" enctype="multipart/form-data">‘+ ‘What is your name? <input type="text" name="name" /><br />‘+ ‘What files are you sending? <input type="file" name="files" multiple="multiple" /><br />‘+ ‘<input type="submit" value=http://www.mamicode.com/"send" />‘+>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。