file_obj = request.FILES.get('file', None)
if file_obj:
str_time = time.strftime('%Y-%m-%d_%H_%M_%S')
fname = file_obj.name
#fname = str_time+str(random.randint(0,9999)) + fname[fname.rfind('.'):]
fname = 'my_img'+fname[fname.rfind('.'):]
if os.path.isdir(homedir+'/pub/'+str(users.id)+'/'):
#os.rmdir('C:/hoodbc/')
pass
else :
os.mkdir(homedir+'/pub/'+str(users.id)+'/')
of = open(homedir+'/pub/'+str(users.id)+'/'+fname, 'wb+')
for chunk in file_obj.chunks():
of.write(chunk)
of.close()
python的文件操作很像linux的命令。
过两天再整合多文件上传的组件,现在先将就着。
本文介绍了一个使用Python处理文件上传的过程,包括获取上传文件、生成唯一文件名并保存到指定目录。文中还提到了后续计划整合多文件上传组件。

被折叠的 条评论
为什么被折叠?



