From 07704199616228849c17302f21dd5a5a30dbea66 Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 26 Jan 2018 14:12:33 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cgi-bin/img.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 cgi-bin/img.py (limited to 'cgi-bin/img.py') diff --git a/cgi-bin/img.py b/cgi-bin/img.py new file mode 100644 index 0000000..7a7751f --- /dev/null +++ b/cgi-bin/img.py @@ -0,0 +1,52 @@ +#!C:\Python364\python3.exe +# -*- coding: utf-8 -*- +import sys, codecs +import cgi, cgitb +import pymysql +import issuedb +from issuedb import IssueDBFactory +import os +import path +from path import Path +import time +sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer) + +form = cgi.FieldStorage() + +fileobj = form['upload'] +callback = form.getvalue("CKEditorFuncNum") +fname, fext = os.path.splitext(fileobj.filename) + +def randname(): + return int(time.time()); + +rnd_name = '%s%s' % (randname(), fext) +filepath = Path.img(rnd_name) + +# 检查路径是否存在,不存在则创建 +dirname = os.path.dirname(filepath) +url = "" +error = "" +if not os.path.exists(dirname): + try: + os.makedirs(dirname) + except: + error = 'ERROR_CREATE_DIR' +elif not os.access(dirname, os.W_OK): + error = 'ERROR_DIR_NOT_WRITEABLE' +if not error: + open(filepath, 'wb').write(fileobj.file.read()) + #url = url_for('static', filename='%s/%s' % ('upload', rnd_name)) + url = Path.url("imgs/" + rnd_name) + +res = """ + + + +""" % (callback, url, error) + +print("Content-type:text/html\n") +print(res) + -- cgit v1.1-26-g67d0