服务器端文件浏览 [英] Server Side File Browsing

查看:50
本文介绍了服务器端文件浏览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Web 应用程序,该应用程序从一组文本文件中读取数据并将其映射到 MySQL 数据库.

I'm working on a web app that reads data from a set of text files and maps it to a MySQL database.

目前,该表单需要手动输入文件路径,但我想在此字段中添加一个文件选择器,以减少该部分设置的繁琐.

Currently, the form requires manual input of the file path, but I would like to add a file chooser to this field to make that part of the setup a little less tedious.

我发现的所有解决方案都允许选择单个文件,但我正在寻找一种允许使用输入模式的解决方案,因为我们的大多数工作都要求我们一次性从服务器中提取多个文件.

The solutions I've found all allow selection of a single file, but I'm looking for one that will allow the use of input patterns, as most of our jobs require us to pull multiple files off the server in one go.

非常感谢您对此事的任何帮助.

Any help in this matter is much appreciated.

推荐答案

我进行了大量搜索和一些工作,但我找到了一个合理可行的答案.

It took a lot of searching and some work around, but I found a reasonably viable answer for this.

我面临的最大问题是浏览服务器端文件.我在 A Beautiful Site 上找到了一个 jQuery 插件,解决了这个问题.

The biggest problem I faced was browsing server-side files. I found a jQuery plugin at A Beautiful Site that solved that issue.

这是一个 AJAX 文件浏览器,带有用于 JSP、PHP、ASP 等的服务器端连接器脚本.

It's an AJAX file browser with server-side connector scripts for JSP, PHP, ASP, and others.

我使用以下脚本构建了 webapp 的文件树:

I built the webapp's file tree using the following script:

  $(document).ready( function() {
    $('#loadFolderTree').fileTree({

        root: '/server_root/subfolder/tree_root',
        script: '/js/jquery_file_tree/connectors/jqueryFileTree.jsp',
        multiFolder: false,

    });    
  });

这个脚本的好处在于它以字符串形式返回选定的文件路径.通过对脚本的默认文件处理进行一些小的添加,我能够使用以下代码将返回的文件路径写入适当的表单字段:

The nice thing about this script is that it returns the selected file path as a String. With some minor additions to the script's default file handling, I was able to write the returned file path to the appropriate form field with the following code:

}, function(file) {
            var loadPat = document.getElementById("loadPattern");
            loadPat.value = file.replace("/server_root/subfolder/tree_root/", "");

由于已经构建了表单来处理相对于根目录的文件,因此无需打印整个路径,因此最后一段代码将路径修剪到根目录,并将表单值设置为字符串的剩余内容.

Since the form is already built to handle files relative to the root, there is no need to print the entire path, so this last piece of code trims off the path up to the root directory, and sets the form value to the remaining content of the String.

最重要的是,返回的字符串在表单中是可编辑的,允许用户将 input-file-1.txt 的返回更改为 input-file*.txt 并在一次运行中导入多个文件.

Most importantly, the returned string is editable in the form which allows users to change a return of input-file-1.txt to input-file*.txt and import multiple files in one run.

这是最终结果:

  $(document).ready( function() {
    $('#loadFolderTree').fileTree({

        root: '/server_root/subfolder/tree_root',
        script: '/js/jquery_file_tree/connectors/jqueryFileTree.jsp',
        multiFolder: false,

    }, function(file) {
        var loadPat = document.getElementById("loadPattern");
        loadPat.value = file.replace("/server_root/subfolder/tree_root/", "");

    });    
  });

这篇关于服务器端文件浏览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆