Esempio n. 1
0
def imageUp(funname,site,request):
    result=getResult()
    f=request.FILES[fieldname]
    if not isAllowFiles(f.name,imgtype):
        result['state']=errorInfo['TYPE']
    elif not isAllowSize(f.size,maxSize) :
        result['state']=errorInfo['SIZE']
    else:

        # parser=ImageFile.Parser()
        # for chunk in f.chunks():
        #     parser.feed(chunk)
        # img=parser.close()
        newfilename=''
        ufile=UeditorFile()
        try:
            newfilename=getSaveName(UPLOAD_ROOT+str(site.get('id'))+'/',f.name)
            ufile.filename=f.name
            ufile.realfilename=newfilename
            ufile.size=f.size
            ufile.title=request.POST.get('pictitle','')
            ufile.type='image'
            ufile.site=WebSiteInfo.objects.get(pk=site.get('id'))
            ufile.user=request.user
            ufile.save()
            # img.save(UPLOAD_ROOT+str(site.get('id'))+'/'+newfilename)
            fileatt=open(UPLOAD_ROOT+str(site.get('id'))+'/'+newfilename,'wb+')
            for chunk in f.chunks():
                fileatt.write(chunk)
            fileatt.close()
        except Exception,e:
            ufile.delete()
            result['state']=errorInfo['DIR']

        else:
Esempio n. 2
0
def fileUp(funname,site,request):
    result=getResult()
    f=request.FILES[fieldname]
    if not isAllowFiles(f.name,filetype):
#        result['state']=errorInfo['TYPE']
        result['state']=u'只允许上传 rar 和 zip 格式的数据'
    elif not isAllowSize(f.size,filemaxSize) :
        result['state']=u'最大允许上传1Mb的文件'
    else:
        newfilename=''
        ufile=UeditorFile()
        try:
            newfilename=getSaveName(UPLOAD_ROOT+str(site.get('id'))+'/',f.name)
            ufile.filename=f.name
            ufile.realfilename=newfilename
            ufile.size=f.size
            ufile.title=request.POST.get('pictitle','')
            ufile.type='att'
            ufile.site=WebSiteInfo.objects.get(pk=site.get('id'))
            ufile.user=request.user
            ufile.save()
            fileatt=open(UPLOAD_ROOT+str(site.get('id'))+'/'+newfilename,'wb+')
            for chunk in f.chunks():
                fileatt.write(chunk)
            fileatt.close()

        except Exception,e:
            ufile.delete()
            result['state']=errorInfo['DIR']

        else:
Esempio n. 3
0
def adminInfo_save(site,request):
    if 'POST'!=request.method.upper():
    #        raise Http404()
    #        return HttpResponse(json.dumps({'ss':544}))
        return HttpResponseRedirect('/blog/Admin/AdminInfo')
    viewmap={}
    website=WebSiteInfo.objects.get(pk=site.get('id'))
    if website:
        bloguser=website.author
        if bloguser:
            bloguser.desc=request.POST.get('content')
            msg=u'保存成功'
            f=request.FILES['pic']
            if f:
                if not isAllowFiles(f.name,["gif" , "png" , "jpg" , "jpeg" , "bmp"]):
                    msg=u'保存失败,图片格式不对。'
                elif not isAllowSize(f.size,220000) :
                    msg=u'保存失败,图片大小过大。'
                else:
                    parser=ImageFile.Parser()
                    for chunk in f.chunks():
                        parser.feed(chunk)
                    img=parser.close()
                    newfilename=''
                    ufile=UeditorFile()
                    try:
                        newfilename=getSaveName(UPLOAD_ROOT+str(site.get('id'))+'/',f.name)
                        ufile.filename=f.name
                        ufile.realfilename=newfilename
                        ufile.size=f.size
                        ufile.title=request.POST.get('pictitle','')
                        ufile.type='image'
                        ufile.site=WebSiteInfo.objects.get(pk=site.get('id'))
                        ufile.user=request.user
                        ufile.save()
                        img.save(UPLOAD_ROOT+str(site.get('id'))+'/'+newfilename)
                    except Exception,e:
                        traceback.print_exc()
                        if ufile.id:
                            ufile.delete()
                        msg=u'保存失败。'
                    else:
                        bloguser.img=UPLOAD_URL+str(site.get('id'))+'/'+newfilename
                        bloguser.save()
            else:
                bloguser.save()
            viewmap['msg']=msg
            userinfo={}
            userinfo['img']=bloguser.img
            userinfo['content']=bloguser.desc
            viewmap['adminInfo']=userinfo
Esempio n. 4
0
def getRemoteImage(funname,site,request):
    result={}
    url=request.POST.get("upfile")
    result['state']=u'远程图片抓取成功'
    arr=url.split(ue_separate_ue)
    outSrc=[]
    for i,uri in enumerate(arr):
        outSrc.append('')
        if not isAllowFiles(uri,imgtype):
            result['state']=errorInfo['TYPE']
            continue
        fileuri=urllib.urlopen(uri)
        if fileuri.getcode()==200 and fileuri.headers.type.find('image')!=-1:
            # parser=ImageFile.Parser()
            # for chunk in fileuri.readlines():
            #     parser.feed(chunk)
            # fileuri.close()
            size=int(fileuri.headers.dict['content-length'])
            # img=parser.close()
            newfilename=''
            ufile=UeditorFile()
            try:
                newfilename=getSaveName(UPLOAD_ROOT+str(site.get('id'))+'/',uri.split('/')[-1])
                ufile.filename=uri.split('/')[-1]
                ufile.realfilename=newfilename
                ufile.size=size
                ufile.title=''
                ufile.type='image'
                ufile.site=WebSiteInfo.objects.get(pk=site.get('id'))
                ufile.user=request.user
                ufile.save()
                # img.save(UPLOAD_ROOT+str(site.get('id'))+'/'+newfilename)
                fileatt=open(UPLOAD_ROOT+str(site.get('id'))+'/'+newfilename,'wb+')
                for chunk in fileuri.readlines():
                    fileatt.write(chunk)
                fileatt.close()
                fileuri.close()
            except Exception,e:
                ufile.delete()
                result['state']=errorInfo['DIR']
                continue
            else:
            #                result['state']=errorInfo['SUCCESS']
                outSrc.insert(i,str(site.get('id'))+'/'+newfilename)
            pass
        else:
            result['state']=u'图片地址错误'
            continue
Esempio n. 5
0
def managePaperImage_upload(site,request):
    '''
    http://blog.csdn.net/jbgtwang/article/details/6454023
    '''
    f=request.FILES['imgfile']
    parser=ImageFile.Parser()
    for chunk in f.chunks():
        parser.feed(chunk)
    img=parser.close()
    newfilename=''
    ufile=UeditorFile()
    try:
        newfilename=getSaveName(UPLOAD_ROOT+str(site.get('id'))+'/','big'+f.name)
        ufile.filename=f.name
        ufile.realfilename=newfilename
        ufile.size=f.size
        ufile.title=request.POST.get('pictitle','')
        ufile.type='image'
        ufile.site=WebSiteInfo.objects.get(pk=site.get('id'))
        ufile.user=User.objects.get(pk=request.GET.get('userid'))
        ufile.save()
        paperImage=PaperImage.objects.get(pk=request.REQUEST.get('imgid'))
        w,h=img.size
        if f.name.split('.')[-1].lower()!='gif':
            if w>PAPERIMAGE_SIZE_WIDTH_BIG:
                nw=int(w*((PAPERIMAGE_SIZE_WIDTH_BIG*1.0)/(w*1.0)))
                nh=int(h*((nw*1.0)/(w*1.0)))
                img=img.resize((nw,nh))
                w=nw
                h=nh
                img.save(UPLOAD_ROOT+str(site.get('id'))+'/'+newfilename)
            else:
                img.save(UPLOAD_ROOT+str(site.get('id'))+'/'+newfilename)
            paperImage.img=newfilename

            ####
            newfilename=getSaveName(UPLOAD_ROOT+str(site.get('id'))+'/','mid'+newfilename)
            if w>PAPERIMAGE_SIZE_WIDTH_MID:
                nw=int(w*((PAPERIMAGE_SIZE_WIDTH_MID*1.0)/(w*1.0)))
                nh=int(h*((nw*1.0)/(w*1.0)))
                img=img.resize((nw,nh))
                w=nw
                h=nh
                img.save(UPLOAD_ROOT+str(site.get('id'))+'/'+newfilename)
            else:
                img.save(UPLOAD_ROOT+str(site.get('id'))+'/'+newfilename)
            paperImage.imgmid=newfilename
            ####
            newfilename=getSaveName(UPLOAD_ROOT+str(site.get('id'))+'/','small'+newfilename)
            if h>PAPERIMAGE_SIZE_HEIGH_SMALL:
                nh=int(h*((PAPERIMAGE_SIZE_HEIGH_SMALL*1.0)/(h*1.0)))
                nw=int(w*((nh*1.0)/(h*1.0)))
                img=img.resize((nw,nh))
                img.save(UPLOAD_ROOT+str(site.get('id'))+'/'+newfilename)
            else:
                img.save(UPLOAD_ROOT+str(site.get('id'))+'/'+newfilename)
            paperImage.imgsmall=newfilename
        else:
            img.save(UPLOAD_ROOT+str(site.get('id'))+'/'+newfilename)
            paperImage.img=newfilename
            paperImage.imgmid=newfilename
            paperImage.imgsmall=newfilename
        paperImage.save()
    except Exception,e:
        ufile.delete()
        return Http404()