Created
September 16, 2011 12:04
-
-
Save azyobuzin/1221958 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!C:\Python27\python.exe | |
# -*- coding: utf-8 -*- | |
import cgi, os, sys, string, random | |
result = "" | |
statuscode = "200 OK" | |
try: | |
import msvcrt | |
msvcrt.setmode(0, os.O_BINARY) | |
msvcrt.setmode(1, os.O_BINARY) | |
except ImportError: | |
pass | |
def create_filename(): | |
chars = string.ascii_letters + string.digits | |
return "".join([ random.choice(chars) for i in range(8) ]) + ".txt" | |
form = cgi.FieldStorage() | |
if form.has_key("file"): | |
item = form["file"] | |
if item.file: | |
try: | |
fout = file(os.path.join("upfiles", create_filename()), "wb") | |
#100KiBまでしかうpさせない | |
chunk = item.file.read(1024 * 100) | |
fout.write(chunk) | |
fout.close() | |
result = "正しくアップロードされました。" | |
except Exception as e: | |
result = "アップロード中にエラーが発生しました: " + type(e).__name__ + " " + e.message | |
statuscode = "500 Internal Server Error" | |
else: | |
result = "ファイルを指定してください。" | |
statuscode = "400 Bad Request" | |
print("Status: " + statuscode) | |
print("Content-Type: application/xml") | |
print("""<?xml version="1.0" encoding="utf-8"?>""") | |
print("<message>" + result + "</message>") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment