【问题标题】:BlueImp jQuery FIle Upload - Adding addition data to each fileBlueImp jQuery 文件上传 - 向每个文件添加附加数据
【发布时间】:2013-05-09 22:25:19
【问题描述】:

我最近进行了一个项目来创建一个简单的多文件上传系统,您可以在其中为每个上传的文件分配一个标题。现在我被推荐使用 Blueimp 的 jQuery 文件上传器,因为它提供了拖放功能。

所以这就是我感到困惑的地方。我在 GitHub Link here 上查看了 blueimp 给出的教程或描述。我可以添加一个附加字段,但这适用于所有上传的文件。 (我正在使用 CodeIgniter 将文件处理到 DB)。

那么我将如何为添加的每个文件添加单独的标题?因为我无法理解 github 上的 tut。 (也许是一个 jsfiddle 示例,我可以从中学习?)

编辑*

现在我已经设法添加了额外的输入框......最后添加起来相当简单(doh!)。所以这就是我的 index.html 文件中的内容

<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-upload fade">
        <td>
            <span class="preview"></span>
        </td>
        <td>
            <p class="name">{%=file.name%}</p>
            {% if (file.error) { %}
                <div><span class="label label-important">Error</span> {%=file.error%}</div>
            {% } %}
        </td>
        <td class="title"><label>File Title: <input name="title[]" required="required"></label></td>
        <td>
            <p class="size">{%=o.formatFileSize(file.size)%}</p>
            {% if (!o.files.error) { %}
                <div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="bar" style="width:0%;"></div></div>
            {% } %}
        </td>
        <td>
            {% if (!o.files.error && !i && !o.options.autoUpload) { %}
                <button class="btn btn-primary start">
                    <i class="icon-upload icon-white"></i>
                    <span>Start</span>
                </button>
            {% } %}
            {% if (!i) { %}
                <button class="btn btn-warning cancel">
                    <i class="icon-ban-circle icon-white"></i>
                    <span>Cancel</span>
                </button>
            {% } %}
        </td>
    </tr>
{% } %}
</script>

我也在 main.js 文件的底部添加了这个

$('#fileupload').bind('fileuploadsubmit', function (e, data) {
    var inputs = data.context.find(':input');
    if (inputs.filter('[required][value=""]').first().focus().length) {
        return false;
    }
    data.formData = inputs.serializeArray();

我的下一个问题是我现在如何将标题指定为文件名?

【问题讨论】:

    标签: php jquery file-upload blueimp


    【解决方案1】:

    只需添加不带扩展名的文件名作为文本字段的值。

    &lt;td class="title"&gt;&lt;label&gt;File Title: &lt;input name="title[]" value="{%= file.name.split('/').pop().split('.').shift()%}"  required="required"&gt;&lt;/label&gt;&lt;/td&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-21
      • 1970-01-01
      相关资源
      最近更新 更多