3 # FROM: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/273844
6 import cgitb; cgitb.enable()
10 UPLOAD_DIR = "/tmp/upload/"
11 form = cgi.FieldStorage()
16 dbg.append(str(dbgstr))
18 def save_uploaded_file(form_field, upload_dir):
20 if not form.has_key(form_field):
21 debug("didn't find it! (1)")
23 fileitem = form[form_field]
25 debug(form.getvalue(form_field, ""))
26 debug(fileitem.__dict__)
27 debug("didn't find it! (2)")
29 fout = file(os.path.join(upload_dir, fileitem.filename), 'wb')
31 chunk = fileitem.file.read(100000)
39 if form.has_key("fileFields"):
40 fval = str(form.getvalue("fileFields", ""))
41 fileFields = fval.split(",")
42 debug("'fileCount': '" + str(len(fileFields)) + "',")
43 for field in fileFields:
44 debug("'fileField' : '"+field + "',")
45 save_uploaded_file(str(field).strip(), UPLOAD_DIR)
48 debug("'retval': " + retval)
50 print """Content-Type: text/html
57 <textarea style="width: 100%; height: 100px;">{ %s }</textarea>
60 """ % (string.join(dbg, "\n"))