def POST(self): args = web.input(file = {}, dirname = None) x = args dirname = args.dirname if 'file' in x: if x.file.filename == "": raise web.seeother("//fs/%s" % quote(dirname)) xutils.makedirs(dirname) filename = xutils.quote(os.path.basename(x.file.filename)) filepath = os.path.join(dirname, filename) with open(filepath, "wb") as fout: # fout.write(x.file.file.read()) for chunk in x.file.file: fout.write(chunk) raise web.seeother("/fs/%s" % quote(dirname))
def POST(self): file = xutils.get_argument("file", {}) type = xutils.get_argument("type", "normal") prefix = xutils.get_argument("prefix", "") filepath = "" filename = "" # print_env() if not hasattr(file, "filename") or file.filename == "": return xtemplate.render("file/upload_file.html", filepath = filepath, filename = filename) filename = file.filename # Fix IE HMTL5 API拿到了全路径 filename = os.path.basename(filename) quoted_filename = xutils.quote(filename) filepath, webpath = get_upload_file_path(quoted_filename, prefix=prefix) with open(filepath, "wb") as fout: # fout.write(x.file.file.read()) for chunk in file.file: fout.write(chunk) if type == "html5": return dict(success=True, message="上传成功", link=get_link(filename, webpath)) return xtemplate.render("file/upload_file.html", filepath = webpath, filename = filename, is_img=is_img(filename))
def check_resource(path): if xutils.is_img_file(path): pathlist = path.split("/") pathlist = map(lambda name: xutils.quote(name), pathlist) uri = "/fs//" + "/".join(pathlist) # print(uri) raise web.seeother(uri) return False
def POST(self): name = xutils.get_argument("name") content = xutils.get_argument("content") dirname = xconfig.SCRIPTS_DIR path = os.path.join(dirname, name) content = content.replace("\r", "") xutils.savetofile(path, content) raise web.seeother("/system/script/edit?name=" + xutils.quote(name))
def check_resource(path): _, ext = os.path.splitext(path) if ext in (".png", ".jpg"): pathlist = path.split("/") pathlist = map(lambda name: xutils.quote(name), pathlist) uri = "/" + "/".join(pathlist) # print(uri) raise web.seeother(uri) return False
def POST(self): path = xutils.get_argument("path", "") content = xutils.get_argument("content", "") if content == "" or path == "": raise web.seeother("/fs/") else: content = content.replace("\r\n", "\n") xutils.savetofile(path, content) raise web.seeother("/code/edit?path=" + xutils.quote(path))
def edit_POST(self, path): path = xutils.unquote(path) params = web.input(content=None) content = params.get("content") new_name = params.get("new_name") old_name = params.get("old_name") if new_name != old_name: print("rename %s to %s" % (old_name, new_name)) dirname = os.path.dirname(path) realdirname = os.path.join(WIKI_PATH, dirname) oldpath = os.path.join(realdirname, old_name) newpath = os.path.join(realdirname, new_name) os.rename(oldpath, newpath) realpath = newpath path = dirname + "/" + new_name else: realpath = os.path.join(WIKI_PATH, path) print(path, content) xutils.backupfile(realpath, rename=True) xutils.savefile(realpath, content) raise web.seeother("/wiki/" + xutils.quote(path))