-
Notifications
You must be signed in to change notification settings - Fork 1
/
upload_file.py
47 lines (38 loc) · 1.31 KB
/
upload_file.py
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
import web
from web import form
render = web.template.render('templates/')
urls = ('/', 'index')
app = web.application(urls, globals())
myform = form.Form(
form.Dropdown('mydrop', [('value1', 'first server'), ('value2', 'second server'), ('value3', 'third server')]),
form.Textbox("middle_server"),
form.Textbox("middle_port",
form.regexp('\d+', 'Usually port 22')),
form.File('myfile'))
class index:
def GET(self):
form = myform()
# make sure you create a copy of the form by calling it (line above)
# Otherwise changes will appear globally
return render.formtest(form)
def POST(self):
toshow=''
form = myform()
if not form.validates():
return render.formtest(form)
else:
x = web.input(myfile={})
filedir = '/tmp'
if 'myfile' in x:
filepath=x.myfile.filename.replace('\\','/')
filename=filepath.split('/')[-1]
file_send = '/tmp/' + filename
try:
fout = open(filedir +'/'+ filename,'w')
fout.write(x.myfile.file.read())
fout.close()
except IOError:
pass
if __name__=="__main__":
web.internalerror = web.debugerror
app.run()