File
提供对站点内磁盘文件的操作
下面是一个完整的文件管理系统, 相关的案例可以在市场中找到
<script env="server">
if (k.request.method = "POST") {
if (k.request.files.length > 0) {
var file = k.request.files[0];
var filename = file.fileName;
if (filename) {
if (k.request.folder) {
filename = k.request.folder + "\\" + filename;
}
k.file.writeBinary(filename, file.bytes);
}
}
if (k.request.createFolder) {
k.file.createFolder(k.request.createFolder, k.request.folder);
}
var folder = k.request.Folder
if (k.request.oldFolder && k.request.newFolder) {
oldFolder = folder ? folder + "//" + k.request.oldFolder : k.request.oldFolder
newFolder = folder ? folder + "//" + k.request.newFolder : k.request.newFolder
k.file.renameFolder(oldFolder, newFolder)
}
if (k.request.oldFile && k.request.newFile) {
oldFile = folder ? folder + "//" + k.request.oldFile : k.request.oldFile
newFile = folder ? folder + "//" + k.request.newFile : k.request.newFile
k.file.rename(oldFile, newFile)
}
}
if (k.request.deleteData) {
var folders = k.request.deleteData.replace(/\[|]/g, '').split(',')
folders.forEach((f) => {
if (f.indexOf('.') !== -1) {
k.file.delete(f);
} else {
k.file.deleteFolder(f)
}
})
}
var allfiles = k.file.getAllFiles();
var folderFiles;
if (k.request.folder) {
folderFiles = k.file.folderFiles(k.request.folder);
}
else {
folderFiles = k.file.folderFiles("\\");
}
var subfolders = k.file.subFolders(k.request.folder);
var currentfolder = "\\";
if (k.request.folder) {
currentfolder = k.request.folder;
}
</script>