ftp服务器太慢配置,索性用python做了一个小网站上传简单多了

index.html

DOCTYPE html>  
<html>  
<head>  
    <title>Upload a zip filetitle>  
head>  
<body>  
    <form method="POST" enctype="multipart/form-data">  
        <input type="file" name="file">  
        <button type="submit">Uploadbutton>  
    form>  
body>  
html>

python 代码

import tornado.web  
import zipfile  
import os  
  
class UploadHandler(tornado.web.RequestHandler):  
    
    def get(self):
        self.render("index.html")
        
    def post(self):  
        file_name = self.request.files['file'][0]['filename']  
        body = self.request.files['file'][0]['body']  
        with open(file_name, 'wb') as f:  
            f.write(body)  
          
        # 解压文件  
        with zipfile.ZipFile(file_name, 'r') as zip_ref:  
            zip_ref.extractall()  
          
        self.write('File uploaded and unzipped successfully')  
  
def make_app():  
    return tornado.web.Application([  
        (r"/upload", UploadHandler),  
    ])  
  
if __name__ == "__main__":  
    app = make_app()  
    app.listen(5000)  
    tornado.ioloop.IOLoop.current().start()

你可能感兴趣的:(服务器,python,前端)