(vi) node. JS does a small piece of login and upload pictures

Source: Internet
Author: User

It took a little bit of time to make a small thing, and I hope you understand that node. js is helpful!!!

Server code: Server.js

Var http = require ("http");  var url = require ("url"); function  Start (Route, handle)  {   function onrequest (request, response)  {      var postData =  "";     var pathname  = url.parse (Request.url). Pathname;     console.log ("Request for "  + pathname +  " received.");     if (pathname== '/start ') {//Login method using     request.setencoding ("UTF8");  //Listener     request.addlistener ("Data",  function (Postdatachunk)  {         console.log ("Get All Data:" +postdatachunk);       Postdata += postdatachunk;       console.log (' Account number is: ' + Postdata.split (' & ') [0].split (' = ') [1]+ '   password is:  ' +postdata.split (' & ') [1].SPLIt (' = ') [1]);      });      request.addlistener ("End",  function ()  {       route (handle, pathname, response,  PostData);     }else{//non-logon method using    route (    &NBSP); handle, pathname, response, request);      }    }   http.createserver (ONrequest). Listen (8888);    console.log ("server has  Started. ");  } exports.start = start;

Route code: Router.js

function route (handle, pathname, response, request) {Console.log ("about-to-route a request for" + pathname);   if (typeof handle[pathname] = = = ' function ') {Handle[pathname] (response, request);     } else {Console.log ("No request handler found for" + pathname);     Response.writehead (404, {"Content-type": "Text/html"});     Response.Write ("404 Not Found");   Response.End (); }} exports.route = route;

Path code for access: Index.js

var server = require ("./server"); var router = require ("./router"); var requesthandlers = require ("./requesthandlers"); var handle = {} handle["/"] = Requesthandlers.login; handle["/login"] = Requesthandlers.login; handle["/start"] = Requesthandlers.start; handle["/upload"] = requesthandlers.upload; handle["/show"] = Requesthandlers.show;server.start (Router.route, handle);

Run method Code: Requesthandlers.js

Var querystring = require ("querystring");  var fs = require ("FS");// Get the File Upload module Var formidable = require ("Formidable");  //landing Page Function login (response, PostData)  {   console.log ("request handler  ' login '  was called.");    var body =  ' 

Run:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/5A/DC/wKiom1T-gV3BEQ0UAAFIacnfOn0105.jpg "title=" Qq20150310132738.png "alt=" Wkiom1t-gv3beq0uaafiacnfon0105.jpg "/>

Page Show:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/5A/DC/wKiom1T-gXujYo0XAABzlWlV2qs665.jpg "title=" Qq20150310132830.png "alt=" Wkiom1t-gxujyo0xaabzlwlv2qs665.jpg "/>

After landing:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/5A/DC/wKiom1T-gZLQoaCxAACVrzYU17I519.jpg "title=" Qq20150310132844.png "alt=" Wkiom1t-gzlqoacxaacvrzyu17i519.jpg "/>

Background data:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/5A/DC/wKiom1T-gabTE_4nAAHwwBEQZ6U949.jpg "title=" Qq20150310132905.png "alt=" Wkiom1t-gabte_4naahwwbeqz6u949.jpg "/>

Upload Success Page:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/5A/D7/wKioL1T-guWx_M2-AAMFfyXXmcQ238.jpg "title=" Qq20150310132936.png "alt=" Wkiol1t-guwx_m2-aamffyxxmcq238.jpg "/>

Background data:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/5A/DC/wKiom1T-geaRmkoqAAKhGwN20GY961.jpg "title=" Qq20150310133002.png "alt=" Wkiom1t-gearmkoqaakhgwn20gy961.jpg "/>


These files must be placed in the installation directory of node. js

Here are the uploaded attachments:

This article is from "My dream Fly on the Sky" blog, please be sure to keep this source http://7915791.blog.51cto.com/7905791/1618962

(vi) node. JS does a small piece of login and upload pictures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.