Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

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