3、多文件上传:uploadify在django中的使用(1)
和普通上传区别不大,用flash在上传操作时。django的csrf会报错,就直接在当前的方法给关掉了csrf。
1、
2、
3、
@csrf_exemptdef do_upload(request,action): if action =='my': file_obj = request.FILES.get('Filedata', None) user_id = request.POST.get('blue','') user_info = UserBase.objects.get(id=user_id) if file_obj: fname = file_obj.name this_file_name=file_obj.name fname = user_id+str(time.strftime("%Y-%m-%d-%H-%M-%S"))+str(random.randint(0,9999)) + fname[fname.rfind('.'):] file_types = fname[fname.rfind('.'):] if os.path.isdir(homedir+'/pub/disk/'+user_id): pass else : os.mkdir(homedir+'/pub/disk/'+user_id) of = open(homedir+'/pub/disk/'+user_id+'/'+fname, 'wb+') for chunk in file_obj.chunks(): of.write(chunk) of.close()
elif action=='go_share': if rbac.who(request)=='x': return system.index.login_out(request) else: users = rbac.who(request) if request.POST.getlist("user_name") and request.POST.get("id",""): names = request.POST.getlist("user_name") try: FileUserList.objects.filter(file_id = request.POST.get("id",""),create_user_id=users.id).delete() except: return HttpResponse('ok') for bc in names: file_user = FileUserList() file_user.user_id = bc file_user.file_id = request.POST.get("id","") file_user.create_time = time.strftime("%Y-%m-%d %H:%M:%S") try: file_user_s = FileUserList.objects.filter(file_id = request.POST.get("id",""),user_id = bc,create_user_id=users.id) except: pass #return HttpResponse('okx') else: if len(file_user_s)>0: pass else: user_info = UserBase.objects.filter(id= bc)[0] file_user.true_name = user_info.true_name file_user.create_user_id = users.id file_user.save() return HttpResponse('ok') elif type(request.POST.getlist("user_name")) is types.ListType and request.POST.get("id",""): # user_name data is none, but has id ,so give me del all user info try: FileUserList.objects.filter(file_id = request.POST.get("id",""),create_user_id=users.id).delete() except: return HttpResponse('okx') return HttpResponse('ok')