i'm already solved the problem.
def POST(self):
files = web.input(file_path={})
if 'file_path' in files:
"""setting server side dir"""
homedir = os.getcwd()
filedir = '%s/static/upload/img' %homedir
"""rename filename"""
filepath=files.file_path.replace('\\','/')
ext=filepath.split('.', 1)[1]
now=datetime.datetime.now()
t ="%d%d%d%d%d%d" %(now.year,now.month,now.day,now.hour,now.minute,now.second)
file_name = t+'.'+ext
"""read the imge file as binary format"""
try:
with open(files.file_path, 'rb') as f_in:
data = f_in.read()
f_in.close()
with open(filedir+'/'+file_name, 'wb') as f_out:
f_out.write(data)
f_out.close()
except:
return 'faild'
return '/static/upload/img/'+file_name
在 2013年5月10日星期五UTC+8下午2时37分14秒,Johnny Jiang写道: