-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.py
21 lines (19 loc) · 810 Bytes
/
upload.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import web;from os import path
urls = (
'/', 'post'
)
class post:
def GET(self):
return """<form method='post' enctype='multipart/form-data'><input id='filename' placeholder='filename' name='filename'/><br/><input type='file' name='file' id='file'/><input type='submit' value='upload' name='submit'/><br/></form><br/><a href='/static/'>See other uploaded images</a>"""
def POST(self):
filetosave = web.input()['file']
filename = 'static/'+str(web.input()['filename'])+'.png'
if(path.exists(filename)):
return "File with that name already exists, pick another name."
else:
with open(filename, 'wb') as saved:
saved.write(filetosave)
web.seeother(filename)
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()