def handle_uploaded_file(request): f = request.FILES['file'] filename = "" try: ip = request.META['REMOTE_ADDR'] username = request.session[ip] priority = str(request.POST.get('priority')) if priority == "private": path = settings.FILEPATH + "/private/" + username + "/" else: path = settings.FILEPATH + "/share/" if not os.path.exists(path): os.makedirs(path) print f.name filename = str(f.name.encode('utf-8')) filename = path + filename destination = open(filename, 'wb+') for chunk in f.chunks(): destination.write(chunk) destination.close() mod = filemod.FileMod() value = [ '5', username, 'null', f.name.encode('utf-8'), priority, time.strftime(ISOTIMEFORMAT, time.localtime(time.time())) ] mod.insertFile(value) except Exception, e: traceback.print_exc(file=sys.stdout)
def privatefileList(request): mod = filemod.FileMod() ip = request.META['REMOTE_ADDR'] username = request.session[ip] result = mod.getFileList(['username='******'application/json')
def rmFile(request): username = str(request.GET.get('username')) # ip=request.META['REMOTE_ADDR'] priority = str(request.GET.get('priority')) if priority == 'private': filepath = settings.FILEPATH + "/private/" + username + "/" elif priority == 'share': filepath = settings.FILEPATH + "/share/" filename = str(request.GET.get('filename')) filename = urllib.unquote(filename) conditions = ['filename=' + filename, 'username='******'application/json') else: result = {"data": "fail", "status": -1} return HttpResponse(json.dumps(result), content_type='application/json')
def AllfileList(request): mod = filemod.FileMod() result = {"data": mod.getFileList(), "status": 1} return HttpResponse(json.dumps(result), content_type='application/json')
def sharefileList(request): mod = filemod.FileMod() result = mod.getFileList(['priority=share']) result = {"data": result, "status": 1} return HttpResponse(json.dumps(result), content_type='application/json')