1 Star 0 Fork 7

manongyihao / upanddown

forked from lanceadd / upanddown 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test.py 1.51 KB
一键复制 编辑 原始数据 按行查看 历史
manongyihao 提交于 2023-02-07 21:13 . change format
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from flask import Flask, render_template, request, url_for, send_from_directory, jsonify, redirect
import os
import json
# import sys
# reload(sys)
# sys.setdefaultencoding('utf-8')
app = Flask(__name__)
# ALLOWED_EXTENSTIONS = set(['png', 'jpg', 'jpeg', 'gif'])
download_floder = './upload/'
def allow_file(filename):
allow_list = ['png', 'PNG', 'jpg', 'doc', 'docx', 'txt', 'pdf', 'PDF', 'xls', 'rar', 'exe', 'md', 'zip', 'html']
suffix = filename.split('.')
return len(suffix) > 1 and suffix[1] in allow_list
@app.route('/main')
@app.route('/')
@app.route('/index')
def home():
return render_template('index.html')
@app.route('/getlist')
def getlist():
file_url_list = []
file_list = os.listdir(download_floder)
temple = '<a href="./download/{0}">{0}</a>'
return json.dumps([temple.format(f) for f in os.listdir(download_floder)])
@app.route('/download/<filename>')
def download(filename):
return send_from_directory(download_floder, filename, as_attachment=True)
@app.route('/upload', methods=['POST'])
def upload():
f = request.files['file']
result = 'null'
# print type(file)
if f and allow_file(f.filename):
f.save(os.path.join(download_floder, f.filename))
result = 'OK'
elif f:
result = 'NO'
return render_template('index.html', status=result)
if __name__ == '__main__':
if not os.path.exists(download_floder):
os.makedirs(download_floder)
app.run(debug=True, host='0.0.0.0')
Python
1
https://gitee.com/lmynh/upanddown.git
git@gitee.com:lmynh/upanddown.git
lmynh
upanddown
upanddown
master

搜索帮助