var http = require('http');var formidable = require('formidable');var fs = require('fs');http.createServer(function (req, res) {if (req.url == '/fileupload') {var form = new formidable.IncomingForm();form.parse(req, function (err, fields, files) {var oldpath = files.filetoupload.path;var newpath = 'C:/Users/Your Name/' + files.filetoupload.name;fs.rename(oldpath, newpath, function (err) {if (err) throw err;res.write('File uploaded and moved!');res.end();});});} else {res.writeHead(200, {'Content-Type': 'text/html'});res.write('
');return res.end();}}).listen(8080);
Submitted July 31, 2018 at 06:38AM by smiles_low
No comments:
Post a Comment