blob: a13656fa1b0abb0f850e5b37fe72b45253a8d65d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#!/usr/bin/python
# FROM: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/273844
import cgi
import cgitb; cgitb.enable()
import os, sys
import string
UPLOAD_DIR = "/tmp/upload/"
form = cgi.FieldStorage()
dbg = []
def debug(dbgstr):
dbg.append(str(dbgstr))
def save_uploaded_file(form_field, upload_dir):
global form
if not form.has_key(form_field):
debug("didn't find it! (1)")
return
fileitem = form[form_field]
if not fileitem.file:
debug(form.getvalue(form_field, ""))
debug(fileitem.__dict__)
debug("didn't find it! (2)")
return
fout = file(os.path.join(upload_dir, fileitem.filename), 'wb')
while 1:
chunk = fileitem.file.read(100000)
if not chunk: break
fout.write (chunk)
fout.close()
retval = "false";
fileFields = ""
if form.has_key("fileFields"):
fval = str(form.getvalue("fileFields", ""))
fileFields = fval.split(",")
debug("'fileCount': '" + str(len(fileFields)) + "',")
for field in fileFields:
debug("'fileField' : '"+field + "',")
save_uploaded_file(str(field).strip(), UPLOAD_DIR)
retval = "true";
debug("'retval': " + retval)
print """Content-Type: text/html
<html>
<head>
</head>
<body>
<textarea style="width: 100%; height: 100px;">{ %s }</textarea>
</body>
</html>
""" % (string.join(dbg, "\n"))
|