source: Dev/trunk/src/client/dojo/tests/io/upload.cgi @ 483

Last change on this file since 483 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

  • Property svn:executable set to *
File size: 1.4 KB
Line 
1#!/usr/bin/python
2
3# FROM: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/273844
4
5import cgi
6import cgitb; cgitb.enable()
7import os, sys
8import string
9
10UPLOAD_DIR = "/tmp/upload/"
11form = cgi.FieldStorage()
12
13dbg = []
14
15def debug(dbgstr):
16        dbg.append(str(dbgstr))
17
18def 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
36retval = "false";
37fileFields = ""
38
39if 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                # Uncomment the line below to really test file save.
46                # You may need to modify UPLOAD_DIR above.
47                # save_uploaded_file(str(field).strip(), UPLOAD_DIR)
48        retval = "true";
49
50debug("'retval': " + retval)
51
52print """Content-Type: text/html
53
54
55<html>
56        <head>
57        </head>
58        <body>
59            <textarea style="width: 100%%; height: 100px;">{ %s }</textarea>
60        </body>
61</html>
62""" % (string.join(dbg, "\n"))
Note: See TracBrowser for help on using the repository browser.