Пример #1
0
    def POST(self, id):
        size = 128, 128
        x = web.input(myfile={})
        filedir = 'static/images/uploads/' + id + "/"  # change this to the directory you want to store the file in.

        if 'myfile' in x:  # to check if the file-object is created
            filepath = x.myfile.filename.replace(
                '\\',
                '/')  # replaces the windows-style slashes with linux ones.
            filename = filepath.split(
                '/'
            )[-1]  # splits the and chooses the last part (the filename with extension)

            if os.path.exists(filedir):
                shutil.rmtree(filedir)

            os.makedirs(filedir)

            fout = open(
                filedir + filename, 'w'
            )  # creates the file where the uploaded file should be stored
            fout.write(x.myfile.file.read()
                       )  # writes the uploaded file to the newly created file.
            fout.close()  # closes the file, upload complete.

            size = 512, 512

            im = Image.open(filedir + filename)
            im.thumbnail(size)
            im.save(filedir + filename.split(',')[0] + "-thumb.jpg")
            blog.update_thumb_for_post(
                id, "/" + filedir + filename.split(',')[0] + "-thumb.jpg")
Пример #2
0
    def POST(self, id):
        if user.logged(session):
            if session.privilege == 2:
                filedir = 'static/images/uploads/'+str(id)+"/" # change this to the directory you want to store the file in.
                blog.update_thumb_for_post(id, None)

                if os.path.exists(filedir):
                    shutil.rmtree(filedir)
Пример #3
0
    def POST(self, id):
        if user.logged(session):
            if session.privilege == 2:
                filedir = 'static/images/uploads/' + str(
                    id
                ) + "/"  # change this to the directory you want to store the file in.
                blog.update_thumb_for_post(id, None)

                if os.path.exists(filedir):
                    shutil.rmtree(filedir)
Пример #4
0
    def POST(self, id):
        size = 128, 128
        x = web.input(myfile={})
        filedir = 'static/images/uploads/'+id+"/" # change this to the directory you want to store the file in.

        if 'myfile' in x: # to check if the file-object is created
            filepath=x.myfile.filename.replace('\\','/') # replaces the windows-style slashes with linux ones.
            filename=filepath.split('/')[-1] # splits the and chooses the last part (the filename with extension)

            if os.path.exists(filedir):
                shutil.rmtree(filedir)

            os.makedirs(filedir)

            fout = open(filedir + filename,'w') # creates the file where the uploaded file should be stored
            fout.write(x.myfile.file.read()) # writes the uploaded file to the newly created file.
            fout.close() # closes the file, upload complete.

            size = 512, 512

            im = Image.open(filedir + filename)
            im.thumbnail(size)
            im.save(filedir + filename.split(',')[0]+"-thumb.jpg")
            blog.update_thumb_for_post(id, "/"+filedir + filename.split(',')[0]+"-thumb.jpg")