文件夹数据库处理逻辑

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/09/web%E4%B8%8A%E4%BC%A0%E6%96%87%E4%BB%B6%E5%A4%B9/

web上传文件夹的更多相关文章

  1. Java+web+上传文件夹

    用JAVA实现大文件上传及显示进度信息 ---解析HTTP MultiPart协议 (本文提供全部源码下载,请访问 https://github.com/1269085759/up6-jsp-mysq ...

  2. java+web上传文件夹内的所有文件

    javaweb上传文件 上传文件的jsp中的部分 上传文件同样可以使用form表单向后端发请求,也可以使用 ajax向后端发请求 1.通过form表单向后端发送请求 <form id=" ...

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

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

  4. Web上传文件的原理及实现

    现在有很多Web程序都有上传功能,实现上传功能的组件或框架也很多,如基于java的Commons FileUpload.还有Struts1.x和Struts2中带的上传文件功能(实际上,Struts2 ...

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

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

  6. java上传文件夹文件

    这里只写后端的代码,基本的思想就是,前端将文件分片,然后每次访问上传接口的时候,向后端传入参数:当前为第几块文件,和分片总数 下面直接贴代码吧,一些难懂的我大部分都加上注释了: 上传文件实体类: 看得 ...

  7. java实现上传文件夹

    我们平时经常做的是上传文件,上传文件夹与上传文件类似,但也有一些不同之处,这次做了上传文件夹就记录下以备后用. 首先我们需要了解的是上传文件三要素: 1.表单提交方式:post (get方式提交有大小 ...

  8. webuploader+上传文件夹

    在web项目中上传文件夹现在已经成为了一个主流的需求.在OA,或者企业ERP系统中都有类似的需求.上传文件夹并且保留层级结构能够对用户行成很好的引导,用户使用起来也更方便.能够提供更高级的应用支撑. ...

  9. 上传文件夹 vue

    ASP.NET上传文件用FileUpLoad就可以,但是对文件夹的操作却不能用FileUpLoad来实现. 下面这个示例便是使用ASP.NET来实现上传文件夹并对文件夹进行压缩以及解压. ASP.NE ...

随机推荐

  1. 【VS开发】免费打工仔:一个完善的ActiveX Web控件教程

    作者 David Marcionek. 翻译 免费打工仔 这个教程可以帮助你快速开发一个ActiveX控件.其中将要讲解关于ActiveX开发的一些基础概念,诸如方法(method).属性(prope ...

  2. AndroidStudio ADB WIFI :adb wifi scan ip address

    笔记本使用Android studio的adb wifi插件时,AS 最下方报 adb wifi scan ip address.一直无法使用. 解决办法: ----在Terminal窗口中输入: a ...

  3. 暴力破解-H3C路由器-MSR900

    作者:zptxwd@gmail.com  最后修改日期2017年5月10日    转载请保留出处 声明,本文仅用于技术交流和学习,不得用于任何商业用途及违法行为.   所暴力破解的设备信息 华三路由器 ...

  4. shell脚本一键部署nginx

    一键部署nginx 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ...

  5. TableLayoutPanel

    1.简单属性 百度经验:https://jingyan.baidu.com/article/9113f81b7966df2b3314c775.html Name属性:tableLayoutPanel经 ...

  6. python3爬取动态网站图片

    思路: 1.图片放在<image>XXX</image>标签中 2.利用fiddler抓包获取存放图片信息的js文件url 3.利用requests库获取html内容,然后获取 ...

  7. php 数组助手类

    ArrayHelper.php <?php /** * php 数组助手类 * Class ArrayHelper * @package app\helper */ class ArrayHel ...

  8. java判断一个单向链表是否有环路

    今天刷LeetCode刷到一道这样的题,详情参见(https://leetcode-cn.com/problems/linked-list-cycle/) ADT: class ListNode { ...

  9. java复习(1)面向对象

    一.面向对象的概念 ----------------------------------------------------- 1.理解面向对象:(1)面向对象是相对于面向过程的语言 (2)面向对象和 ...

  10. HTML-复杂动画和变形

    1.复杂动画 (1)涉及到的属性: animation-name:动画名称: animation-duration:单次动画总时长: animation-timing-function:时间函数: a ...