2013-05-15 61 views
1

我最近開展了一個項目,創建一個簡單的多文件上傳系統,您可以爲每個上傳的文件分配一個標題。現在我建議使用Blueimp的jQuery File上傳器,因爲它提供了拖放功能。BlueImp jQuery FILE上傳 - 添加數據到每個文件

所以這裏是我感到困惑。我看了GitHub Link here上的blueimp給出的教程或描述。我可以添加一個額外的字段,但這適用於上傳的所有文件。 (我使用CodeIgniter來處理文件到數據庫)。

那麼我會如何去添加一個單獨的標題添加到每個文件?因爲我無法理解github上的嘖嘖聲。 (也許的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(); 

下一個問題我已經是我怎麼分配標題作爲文件名了嗎?

回答

2

只需將不帶擴展名的file.name添加爲文本字段的值即可。

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

相關問題