const http = require("http")
const formidable = require("formidable")
const util = require("util")
const fs = require("fs")

const server = http.createServer((req, res) => {
    res.writeHead(200, { "Content-type": "text/html;charset=utf8" })
    if (req.url == "/favicon.ico") return

    if (req.url == "/info") {
        var form = new formidable.IncomingForm();
        form.uploadDir = "./upload"
        form.parse(req, function (err, fields, files) {
            res.writeHead(200, { "content-type": "text/plain;charset=uft8" })
            res.write("上传成功")
            let oldPath = __dirname + "/" + files.files.path
            let newPath = __dirname + "/upload/" + files.files.name
            fs.rename(oldPath, newPath, (err, data) => {
                if (err) {
                    console.log(err)
                    return
                }
                res.end("改名成功")
            })
        })
    }

})

server.listen(2323)

相关文章:

  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2021-06-12
  • 2022-12-23
  • 2021-12-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2021-07-16
  • 2022-01-05
  • 2021-08-28
  • 2022-12-23
相关资源
相似解决方案