文件夹数据库处理逻辑

public class 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","");

return this.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);

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

else if (!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;

}

public void 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) });

}

public void 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/11/14/flash%e4%b8%8a%e4%bc%a0%e8%b6%85%e5%a4%a7%e6%96%87%e4%bb%b6%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88/

Flash上传超大文件解决方案的更多相关文章

  1. B/S上传超大文件解决方案

    4GB以上超大文件上传和断点续传服务器的实现 随着视频网站和大数据应用的普及,特别是高清视频和4K视频应用的到来,超大文件上传已经成为了日常的基础应用需求. 但是在很多情况下,平台运营方并没有大文件上 ...

  2. js上传超大文件解决方案

    需求: 支持大文件批量上传(20G)和下载,同时需要保证上传期间用户电脑不出现卡死等体验: 内网百兆网络上传速度为12MB/S 服务器内存占用低 支持文件夹上传,文件夹中的文件数量达到1万个以上,且包 ...

  3. .net上传超大文件解决方案

    HTML部分 <%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="index.aspx. ...

  4. PHP上传超大文件解决方案

    一提到大文件上传,首先想到的是啥??? 没错,就是修改php.ini文件里的上传限制,那就是upload_max_filesize.修改成合适参数我们就可以进行愉快的上传文件了.当然啦,这是一般情况下 ...

  5. Web上传超大文件解决方案

    文件上传下载,与传统的方式不同,这里能够上传和下载10G以上的文件.而且支持断点续传. 通常情况下,我们在网站上面下载的时候都是单个文件下载,但是在实际的业务场景中,我们经常会遇到客户需要批量下载的场 ...

  6. java上传超大文件解决方案

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

  7. HTML5上传超大文件解决方案

    一.概述 所谓断点续传,其实只是指下载,也就是要从文件已经下载的地方开始继续下载.在以前版本的HTTP协议是不支持断点的,HTTP/1.1开始就支持了.一般断点下载时才用到Range和Content- ...

  8. jsp上传超大文件解决方案

    1,项目调研 因为需要研究下断点上传的问题.找了很久终于找到一个比较好的项目. 在GoogleCode上面,代码弄下来超级不方便,还是配置hosts才好,把代码重新上传到了github上面. http ...

  9. asp.net上传超大文件解决方案

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

随机推荐

  1. # G++出现cannot open output file … : Permission denied问题

    G++出现cannot open output file - : Permission denied问题 这是因为之前的编译运行程序没有退出,导致下一次编译运行无法进行,这应该是命令行下运行才可能出现 ...

  2. X86逆向2:提取按钮通杀特征码

    本章我们将学习特征码的提取与定位,特征码是软件中一段固定的具有标志性的代码片段,特征码的用途非常广泛,最常见的就是杀毒软件的查杀了,查杀就是根据特征码定位技术实现的,再比如木马的免杀也是修改了特征码的 ...

  3. 并不对劲的复健训练-CF1187D

    题目大意 有两个长度为\(n\)的序列\(a_1,...,a_n\),\(b_1,...,b_n\)(\(a,b\leq n\leq 3\times 10^5\) ).一次操作是选取 \([l,r]\ ...

  4. Codeforces 1239A. Ivan the Fool and the Probability Theory

    传送门 注意到连续两个格子如果有相同颜色那么一路过去的都可以确定 比如一开始染了这两个位置: 然后发现后面整片过去都可以确定: 对于横着的情况也是一样,然后就会发现不可能出现横着两个和竖着两个同时都有 ...

  5. SpringBoot 进阶

    SpringBoot 进阶 这里讲两个小方面: 表单验证 AOP 1. 表单验证 SpringBoot 中的表单验证功能步骤如下: 在 controller 类中将用 @PathVariable 和 ...

  6. StoneTab标签页CAD插件 2.6.0

    1.纯属自娱自乐,未做过多的测试: 2.理论上可以用在CAD2010-2012版本,自己用的是WIN10 64位,CAD2012,其他未过测试: 3.尚未打算支持其他版本CAD,主要是电脑只能装WIN ...

  7. Where is __dso_handle defined?

    Where is __dso_handle defined? 来源  https://stackoverflow.com/questions/34308720/where-is-dso-handle- ...

  8. 批量转换epub书籍为mobi电子书

    kindlegen下载地址: http://kindlegen.s3.amazonaws.com/kindlegen_win32_v2_9.zip 原文: http://blog.sina.com.c ...

  9. Nginx自动加载配置文件方案

    nginx自动加载配置文件方案一.nginx+consul+consul-template实现过程:consul作为服务发现软件,consul-template作为nginx配置文件的模板,consu ...

  10. CAN总线简介:如何以编程方式控制汽车

    最近,我正与Voyage公司的朋友合作研究,以实现福特Fusion空调系统(A/C)的编程控制.目前,Voyage公司正努力打造自动驾驶的终极目标:能够以低廉的价格成本和广泛的投放范围,把世界任何地方 ...