文件夹数据库处理逻辑

publicclass DbFolder

{

JSONObject root;

public DbFolder()

{

this.root = new JSONObject();

this.root.put("f_id", "");

this.root.put("f_nameLoc", "根目录");

this.root.put("f_pid", "");

this.root.put("f_pidRoot", "");

}

/**

* 将JSONArray转换成map

* @param folders

* @return

*/

public Map<String, JSONObject> toDic(JSONArray folders)

{

Map<String, JSONObject> dt = new HashMap<String, JSONObject>();

for(int i = 0 , l = folders.size();i<l;++i)

{

JSONObject o = folders.getJSONObject(i);

String id = o.getString("f_id");

dt.put(id, o);

}

return dt;

}

public Map<String, JSONObject> foldersToDic(String pidRoot)

{

//默认加载根目录

String sql = String.format("select f_id,f_nameLoc,f_pid,f_pidRoot from up6_folders where f_pidRoot='%s'", pidRoot);

SqlExec se = new SqlExec();

JSONArray folders = se.exec("up6_folders", sql, "f_id,f_nameLoc,f_pid,f_pidRoot","");

returnthis.toDic(folders);

}

public ArrayList<JSONObject> sortByPid( Map<String, JSONObject> dt, String idCur, ArrayList<JSONObject> psort) {

String cur = idCur;

while (true)

{

//key不存在

if (!dt.containsKey(cur)) break;

JSONObject d = dt.get(cur);//查父ID

psort.add(0, d);//将父节点排在前面

cur = d.getString("f_pid").trim();//取父级ID

if (cur.trim() == "0") break;

if ( StringUtils.isBlank(cur) ) break;

}

return psort;

}

public JSONArray build_path_by_id(JSONObject fdCur) {

String id = fdCur.getString("f_id").trim();//

String pidRoot = fdCur.getString("f_pidRoot").trim();//

//根目录

ArrayList<JSONObject> psort = new ArrayList<JSONObject>();

if (StringUtils.isBlank(id))

{

psort.add(0, this.root);

return JSONArray.fromObject(psort);

}

//构建目录映射表(id,folder)

Map<String, JSONObject> dt = this.foldersToDic(pidRoot);

//按层级顺序排列目录

psort = this.sortByPid(dt, id, psort);

SqlExec se = new SqlExec();

//是子目录->添加根目录

if (!StringUtils.isBlank(pidRoot))

{

JSONObject root = se.read("up6_files"

, "f_id,f_nameLoc,f_pid,f_pidRoot"

, new SqlParam[] { new SqlParam("f_id", pidRoot) });

psort.add(0, root);

}//是根目录->添加根目录

elseif (!StringUtils.isBlank(id) && StringUtils.isBlank(pidRoot))

{

JSONObject root = se.read("up6_files"

, "f_id,f_nameLoc,f_pid,f_pidRoot"

, new SqlParam[] { new SqlParam("f_id", id) });

psort.add(0, root);

}

psort.add(0, this.root);

return JSONArray.fromObject(psort);

}

public FileInf read(String id) {

SqlExec se = new SqlExec();

String sql = String.format("select f_pid,f_pidRoot,f_pathSvr from up6_files where f_id='%s' union select f_pid,f_pidRoot,f_pathSvr from up6_folders where f_id='%s'", id,id);

JSONArray data = se.exec("up6_files", sql, "f_pid,f_pidRoot,f_pathSvr","");

JSONObject o = (JSONObject)data.get(0);

FileInf file = new FileInf();

file.id = id;

file.pid = o.getString("f_pid").trim();

file.pidRoot = o.getString("f_pidRoot").trim();

file.pathSvr = o.getString("f_pathSvr").trim();

return file;

}

public Boolean exist_same_file(String name,String pid)

{

SqlWhereMerge swm = new SqlWhereMerge();

swm.equal("f_nameLoc", name.trim());

swm.equal("f_pid", pid.trim());

swm.equal("f_deleted", 0);

String sql = String.format("select f_id from up6_files where %s ", swm.to_sql());

SqlExec se = new SqlExec();

JSONArray arr = se.exec("up6_files", sql, "f_id", "");

return arr.size() > 0;

}

/**

* 检查是否存在同名目录

* @param name

* @param pid

* @return

*/

public Boolean exist_same_folder(String name,String pid)

{

SqlWhereMerge swm = new SqlWhereMerge();

swm.equal("f_nameLoc", name.trim());

swm.equal("f_deleted", 0);

swm.equal("LTRIM (f_pid)", pid.trim());

String where = swm.to_sql();

String sql = String.format("(select f_id from up6_files where %s ) union (select f_id from up6_folders where %s)", where,where);

SqlExec se = new SqlExec();

JSONArray fid = se.exec("up6_files", sql, "f_id", "");

return fid.size() > 0;

}

public Boolean rename_file_check(String newName,String pid)

{

SqlExec se = new SqlExec();

JSONArray res = se.select("up6_files"

, "f_id"

,new SqlParam[] {

new SqlParam("f_nameLoc",newName)

,new SqlParam("f_pid",pid)

},"");

return res.size() > 0;

}

public Boolean rename_folder_check(String newName, String pid)

{

SqlExec se = new SqlExec();

JSONArray res = se.select("up6_folders"

, "f_id"

, new SqlParam[] {

new SqlParam("f_nameLoc",newName)

,new SqlParam("f_pid",pid)

},"");

return res.size() > 0;

}

publicvoid rename_file(String name,String id) {

SqlExec se = new SqlExec();

se.update("up6_files"

, new SqlParam[] { new SqlParam("f_nameLoc", name) }

, new SqlParam[] { new SqlParam("f_id", id) });

}

publicvoid rename_folder(String name, String id, String pid) {

SqlExec se = new SqlExec();

se.update("up6_folders"

, new SqlParam[] { new SqlParam("f_nameLoc", name) }

, new SqlParam[] { new SqlParam("f_id", id) });

}

}

1.在webuploader.js大概4880行代码左右,在动态生成的input组件的下面(也可以直接搜索input),增加webkitdirectory属性。

function FileUploader(fileLoc, mgr)

{

var _this = this;

this.id = fileLoc.id;

this.ui = { msg: null, process: null, percent: null, btn: { del: null, cancel: null,post:null,stop:null }, div: null};

this.isFolder = false; //不是文件夹

this.app = mgr.app;

this.Manager = mgr; //上传管理器指针

this.event = mgr.event;

this.Config = mgr.Config;

this.fields = jQuery.extend({}, mgr.Config.Fields, fileLoc.fields);//每一个对象自带一个fields幅本

this.State = this.Config.state.None;

this.uid = this.fields.uid;

this.fileSvr = {

pid: ""

, id: ""

, pidRoot: ""

, f_fdTask: false

, f_fdChild: false

, uid: 0

, nameLoc: ""

, nameSvr: ""

, pathLoc: ""

, pathSvr: ""

, pathRel: ""

, md5: ""

, lenLoc: "0"

, sizeLoc: ""

, FilePos: "0"

, lenSvr: "0"

, perSvr: "0%"

, complete: false

, deleted: false

};//json obj,服务器文件信息

this.fileSvr = jQuery.extend(this.fileSvr, fileLoc);

2.可以获取路径

this.open_files = function (json)

{

for (var i = 0, l = json.files.length; i < l; ++i)

{

this.addFileLoc(json.files[i]);

}

setTimeout(function () { _this.PostFirst(); },500);

};

this.open_folders = function (json)

{

for (var i = 0, l = json.folders.length; i < l; ++i) {

this.addFolderLoc(json.folders[i]);

}

setTimeout(function () { _this.PostFirst(); }, 500);

};

this.paste_files = function (json)

{

for (var i = 0, l = json.files.length; i < l; ++i)

{

this.addFileLoc(json.files[i]);

}

};

后端代码逻辑大部分是相同的,目前能够支持MySQL,Oracle,SQL。在使用前需要配置一下数据库,可以参考我写的这篇文章:http://blog.ncmem.com/wordpress/2019/08/07/java超大文件上传与下载/

plupload+上传文件夹的更多相关文章

  1. SFTP 上传文件夹

    使用sftp上传文件夹时若使用如下命令并不work: put /media/Research/GWAS_Class/* Desktop/ 此时,需要添加一个参数 -r, 另外在目标文件夹下面建立一个同 ...

  2. 使用jQuery.FileUpload插件和服Backload组件自定义上传文件夹

    在零配置情况下,文件的上传文件夹是根目录下的Files文件夹,如何自定义文件的上传文件夹呢? □ 在web.config中配置 1: <configuration> 2: <conf ...

  3. svs 在创建的时候 上传文件夹 bin obj 这些不要提交

    svs  在创建的时候 上传文件夹 bin  obj  这些不要提交  右键-去除版本控制并增加到忽略列表

  4. SpringBoot 上传文件夹

    前端代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  5. oss上传文件夹-cloud2-泽优软件

    泽优软件云存储上传控件(cloud2)支持上传整个文件夹,并在云空间中保留文件夹的层级结构,同时在数据库中也写入层级结构信息.文件与文件夹层级结构关系通过id,pid字段关联. 本地文件夹结构 文件 ...

  6. MVC文件上传05-使用客户端jQuery-File-Upload插件和服务端Backload组件自定义上传文件夹

    在零配置情况下,文件的上传文件夹是根目录下的Files文件夹,如何自定义文件的上传文件夹呢? MVC文件上传相关兄弟篇: MVC文件上传01-使用jquery异步上传并客户端验证类型和大小  MVC文 ...

  7. msysgit 上传文件夹,规范化的日常

    在我们第一次成功的上传到github之后,要上传文件夹的我们要在msysgit里输入些什么呢? 选择要上传的文件夹前一项右键点击git bash here 进入msysgit后 首先初始化,输入 gi ...

  8. asp.net FileUpload上传文件夹并检测所有子文件

    1.在FileUpload控件添加一个属性 webkitdirectory=""就可以上传文件夹了 <asp:FileUpload ID="FileUpload1& ...

  9. 基于Ubuntu Server 16.04 LTS版本安装和部署Django之(三):设置上传文件夹权限(这里测试用完全共享)

    基于Ubuntu Server 16.04 LTS版本安装和部署Django之(一):安装Python3-pip和Django 基于Ubuntu Server 16.04 LTS版本安装和部署Djan ...

随机推荐

  1. 三种SpringSecurity方法级别权限控制

    一 JSR-250注解 1.在pom.xml添加 <dependency> <groupId>javax.annotation</groupId> <arti ...

  2. Tkinter(一)

    采集小工具,目前采集主要针对知乎文章与评论,今天刚开始弄,会不断更新完善 目前效果(测试站点 :科技:测试连接:http://zhihu.sogou.com/include/pc/pc/topic/t ...

  3. vim 插件 入门

    vim 手册 vimtutor 精简版本 help user-manual 详细手册 一些vim自带设置 set nu "显示行号 set cursorline "高亮显示当前行 ...

  4. shell习题第19题:最常用的命令

    [题目要求] 查看使用最多的10个命令 [核心要点] history 或者 ~/.bash_history sort uniq [脚本] #!/bin/bash # history就是调用cat ~/ ...

  5. varnish HTTP头

    Cache-Control:指定了缓存如何处理内容.varnish关心max-age参数,并用它来计算对象的TTL.“Cache-Control:no-cache”是被忽略的.Age:varnish添 ...

  6. android中sqlite数据库的基本使用和添加多张表

    看了很多关于android使用sqlite数据库的文章,很多都是介绍了数据库的建立和表的建立,而表通常都是只建立一张,而实际情况我们用到的表可能不止一张,那这种情况下我们又该怎么办呢,好了,下面我教大 ...

  7. Spring实战(四)Spring高级装配中的bean profile

    profile的原意为轮廓.剖面等,软件开发中可以译为“配置”. 在3.1版本中,Spring引入了bean profile的功能.要使用profile,首先要将所有不同的bean定义整理到一个或多个 ...

  8. linux实现一个定时任务

    设置定时任务删除logs脚本数据 编写脚本   touch cleanLogs.sh #! /bin/sh -name "*.log*" -exec rm -f {} \; 使用r ...

  9. 05 Redis-Sentinel

    一.什么是Redis-Sentinel Redis-Sentinel是redis官方推荐的高可用性解决方案当用redis作master-slave的高可用时,如果master本身宕机,redis本身或 ...

  10. SAP成都研究院李三郎:SCP Application Router简介

    今天的文章来自李贝宁(Ben),SAP成都研究院的资深程序猿和架构师. 作为成都研究院里同时精通Java, JavaScript和ABAP这三门编程语言的数位同事之一,Ben曾经先后担任了成都CRM ...