summaryrefslogtreecommitdiff
path: root/cgi-bin/img.py
diff options
context:
space:
mode:
Diffstat (limited to 'cgi-bin/img.py')
-rw-r--r--cgi-bin/img.py52
1 files changed, 52 insertions, 0 deletions
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 = """
+<html>
+<script type="text/javascript">
+ window.parent.CKEDITOR.tools.callFunction(%s, '%s', '%s');
+</script>
+</html>
+""" % (callback, url, error)
+
+print("Content-type:text/html\n")
+print(res)
+