Beispiel #1
0
    def POST(self):
        try:
            authuser()
            x = web.input(myfile={})
            filedir = config.upload_path+str(web.session.Session.user_info['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)
                filename=filename.split('.')[1]

                if filename.lower()=='jpg' or filename.lower()=='png' or filename.lower()=='gif' or filename.lower()=='pdf' or filename.lower()=='zip' or filename.lower()=='tar':
                    filename=up_nowtime()+"."+filename
                    fout = open(filedir +'/'+ filename,'wb') # 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.
                    filename="/"+filedir+"/"+filename
                    web.header("Content-Type","text/html; charset=utf-8;")
                    return "<html><head></head><body>up ok!<img style='width:150px; height:150px;' src='"+filename+"'/>"+filename+"</body></html>"



                else:
                    return "sorry,only put jpg,png,gif,zip,tar,pdf"

        except ValueError:
            return "文件太大了,上传的文件请小于1M,如果要传送大文件,请联系管理员"
Beispiel #2
0
    def POST(self):
        try:
            authuser()
            x = web.input(myfile={})
            filedir = config.upload_path+str(web.session.Session.user_info['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)
                filename=filename.split('.')[1]

                if filename.lower()=='jpg' or filename.lower()=='png' or filename.lower()=='gif':
                    filename=up_nowtime()+"."+filename
                    fout = open(filedir +'/'+ filename,'wb') # 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.
                    filename="/"+filedir+"/"+filename

                    sql="update admin set tx_path='"+filename+"' where user='******'"
                    config.dbw.query(sql)
                    web.session.Session.user_info['tx_path']=filename
                    html='''
                    <script language="JavaScript">
                    alert('图像更新成功!');
          top.location.href='/admin/manager/person/userinfo/';
   </script>
   '''
                    return html
#                    web.redirect('/admin/manager/person/userinfo/')
#                    web.header("Content-Type","text/html; charset=utf-8;")
#                    return "<html><head></head><body>头像更新成功!<img style='width:150px; height:150px;' src='"+filename+"'/>"+filename+"</body></html>"



                else:
                    return "sorry,only put jpg,png,gif"

        except ValueError:
            return "文件太大了,上传的文件请小于1M,如果要传送大文件,请联系管理员"