def savephoto(request): file_name = "" albums = Album.objects.all() i = 0 for file in request.FILES.getlist('photo_img'): try: i += 1 path = "static/upload/img" + time.strftime('/%Y/%m/%d/%H/%M/%S/') if not os.path.exists(path): os.makedirs(path) file_name = path + file.name destination = open(file_name, 'wb+') for chunk in file.chunks(): destination.write(chunk) destination.close() photo = Photo() photo.album_id = request.POST['album'] photo.photo_time = datetime.datetime.now() photo.photo_url = file_name photo.save() except Exception: return render_to_response('backstage/upload/photo.html', {'albums': albums, "error": u"上传第" + i + u"张图片失败"}, context_instance=RequestContext(request)) return HttpResponseRedirect('/upload/photo')
def savephoto(request): file_name = "" for file in request.FILES.getlist('photo_img'): try: path = "static/upload/img" + time.strftime('/%Y/%m/%d/%H/%M/%S/') if not os.path.exists(path): os.makedirs(path) file_name = path + file.name destination = open(file_name, 'wb+') for chunk in file.chunks(): destination.write(chunk) destination.close() except Exception, e: return False photo = Photo() photo.album_id = request.POST['album'] photo.photo_time = datetime.datetime.now() photo.photo_url = file_name photo.save()