hoodbc 发表于 2013-1-19 04:09:55

django文件上传

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 = 'my_img'+fname      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的命令。

过两天再整合多文件上传的组件,现在先将就着。
页: [1]
查看完整版本: django文件上传