Python写的一个文件上传upload
#coding:utf-8
‘‘‘
@date:2014-11-30
@filename:simpleUp.py
‘‘‘
import web
urls=(
‘/‘,‘index‘,
‘/test‘,‘mytest‘,
‘/upload‘,‘Upload‘,
)
app = web.application(urls,locals())
class mytest:
def GET(self):
return "<b><h1>mytest</h1></b>"
class Upload:
def GET(self):
return """<html><head></head><body>
<form method="POST" enctype="multipart/form-data" action="">
<input type="file" name="myfile"/>
<br/>
<input type="submit"/>
</form>
</body></html>"""
def POST(self):
x = web.input(myfile={})
web.debug(x[‘myfile‘].filename)
web.debug(x[‘myfile‘].value)
web.debug(x[‘myfile‘].file.read())
print x[‘myfile‘].filename
print x[‘myfile‘].value
print x[‘myfile‘].file.read()
raise web.seeother(‘/upload‘)
if __name__==‘__main__‘:
app.run()
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。