You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/usr/bin/env node
varhttp=require('http');varformidable=require('formidable');varfs=require('fs');varpath=require('path');varmkdirp=require('mkdirp');varPORT=parseInt(process.argv[2])||8999;varserver=http.createServer(function(req,res){functionerror(err){res.writeHead(500,{'Content-Type': 'text/plain'});res.end(err.toString());//fail}functionnext(from,to){fs.readFile(from,function(err,content){if(err){console.log('s.readFile error');error(err);}else{fs.writeFile(to,content,function(err){if(err){error(err);}res.writeHead(200,{'Content-Type': 'text/plain'});res.end('0');//success});}});}if(req.url=='/'){// show a file upload formres.writeHead(200,{'content-type': 'text/html'});res.end('I\'m ready for that, you know.');}elseif(req.url=='/receiver'&&req.method.toLowerCase()=='post'){varform=newformidable.IncomingForm();form.parse(req,function(err,fields,files){if(err){console.log('form.parse error');error(err);}else{varto=fields['to'];fs.exists(to,function(exists){if(exists){fs.unlink(to,function(err){next(files.file.path,to);});}else{fs.exists(path.dirname(to),function(exists){if(exists){next(files.file.path,to);}else{mkdirp(path.dirname(to),0777,function(err){if(err){error(err);return;}next(files.file.path,to);});}});}});}});}});server.listen(PORT,function(){console.log('receiver listening *:'+PORT);});
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: