如何在BlueImp jQuery下载程序中过滤要下载的文件

how can I filter the files for download in the blueimp jquery download program

本文关键字:下载 过滤 文件 程序 BlueImp jQuery      更新时间:2023-09-26

我正在尝试使用Blueimp jQuery文件上传文件程序 https://github.com/blueimp/jQuery-File-Upload。我已经搜索了wiki和文档,但找不到如何过滤可供下载的文件的答案。

我在经过身份验证的"受保护"区域内使用它。我已经成功地在我上传的所有文件前面加上一个唯一的 id(例如 UID 文件名.jpg ),我将在经过身份验证的会话中提供该 ID。所以我所要做的就是只选择具有正确 UID 的那些。

显示下载表的 jquery 代码是:

<!-- The template to display files available for download -->
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<!--    <tr class="template-download fade">-->
    <tr class="template-download ">
    {% if (file.error) { %}
        <td></td>
        <td class="name"><span>{%=file.name%}</span></td>
        <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
        <td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
    {% } else { %}
        <td class="preview">{% if (file.thumbnail_url) { %}
            <a href="{%=file.url%}" title="{%=file.name%}" rel="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a>
        {% } %}</td>
        <td class="name">
            <a href="{%=file.url%}" title="{%=file.name%}" rel="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a>
        </td>
        <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
        <td colspan="2"></td>
    {% } %}
    <td class="delete">
        <button class="btn btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}">
            <i class="icon-trash icon-white"></i>
            <span>{%=locale.fileupload.destroy%}</span>
        </button>
        <input type="checkbox" name="delete" value="1">
    </td>
</tr>

我在JS/Jquery方面不是很有经验。我将不胜感激关于下一步该做什么的任何想法。是否有人熟悉过滤这些文件的设置/选项。或者,我假设该文件是我怀疑可以过滤的文件名或路径数组。在PHP中,我可能会使用glob函数。有人在JS中对此有任何经验吗?

提前谢谢你,

法案

使用插件 http://sunnywalker.github.io/jQuery.FilterTable/它适用于任何表,并且易于部署。

包括依赖项:

<script src="/path/to/jquery.js"></script>
<script src="/path/to/bindWithDelay.js"></script> <!-- optional -->
<script src="/path/to/jquery.filtertable.js"></script>
<style>
    .filter-table .quick { margin-left: 0.5em; font-size: 0.8em; text-decoration: none; }
    .fitler-table .quick:hover { text-decoration: underline; }
    td.alt { background-color: #ffc; background-color: rgba(255, 255, 0, 0.2); }
</style> <!-- or put the styling in your stylesheet -->

输入代码

<script>
$('table').filterTable(); //if this code appears after your tables; otherwise, include it in your document.ready() code.
</script>

好!祝你好运!