2013-03-25 163 views
3

我已經瞪大眼睛了很多,但還沒有找到我的問題的解決方案。小工具的作者引用了FAQ的最後一個答案,但常見問題解答沒有答案,或者我找不到答案。我想那是從那時起更新的。其他遇到同樣問題的同事問同樣的問題並沒有提供任何解決方案。blueimp文件上傳。如何清理現有的文件清單

不管怎樣,在我來說,我有按鈕圖片的表:

enter image description here

當用戶點擊圖片按鈕中的一個,顯示模態對話框。用戶現在可以管理所選行的圖片。他可以上傳,刪除圖片等。當用戶打開了第二排的對話框上的表,他應該看到第二行只有圖片。它告訴我,每次用戶點擊圖片按鈕查看對話框時,我都必須清除上傳的文件列表。他將從服務器接收與所選行對應的圖片列表。不幸的是,當我檢索所選行的列表時,收到的文件將被添加到現有列表中。

你能告訴我怎樣才能清除列表或重置窗口小部件,而不在服務器端刪除文件?

UPDATE我已經使用下面的一段代碼作爲臨時解決方案。

jQuery.ajax({ 
     url: "<YOUR URL HERE>", 
     dataType: 'json', 
     context: $('#fileupload')[0] 
    }).done(function (result) { 
     jQuery("#fileupload").find(".files").empty(); //this line solves the issue 

     jQuery(this).fileupload('option', 'done').call(this, null, { result: result }); 
    }); 

謝謝。

回答

3

我也嘗試了一小時,以獲得我的上傳工作;)

這裏,我是如何解決這個問題:

$('#html5FileInput').fileupload({ 
    .... 
    add: function (e, data) { 
     $.each(data.files, function (index, file) { 
      var newFileDiv = $(newfileDiv(file.name)); 
      $('#fsUploadProgressHtml5').append(newFileDiv); 

      newFileDiv.find('a').bind('click', function (event) { 
       event.preventDefault(); 
       var uploadFilesBox = $("#fsUploadProgressHtml5"); 
       var remDiv = $(document.getElementById("fileDiv_" + event.data.filename)); 
       removeFileFromArray(event.data.filename); 
       remDiv.remove(); 
       data.files.length = 0; 
       ... 
      }); 

      data.context = newFileDiv; 
     }); 
    ... 
)}; 

,你可以看到我的加載事件中創建我的文件數據集與'newfileDiv(file.name)'。這個創建了有關文件(名稱,大小,...),並且存在從列表中刪除文件的ANKOR所有信息的股利。在這個ankor我綁定一個點擊事件,其中我有刪除實現。

希望這有助於!

+0

謝謝你的答案。這是否意味着沒有本地和智能的方式(如調用方法)來清除列表?你知道爲什麼嗎? – Antipod 2013-03-25 14:14:23

1

我知道這是不是最好的解決方法,但我需要一個非常快速和骯髒......所以這裏就是我所做的(使用jQuery)。

//manually trigger the cancel button for all files...removes anything that isn't uploaded yet 
$('.fileupload-buttonbar .cancel').first().trigger('click'); 

//check the checkbox that selects all files 
if(!$('.fileupload-buttonbar .toggle').first().checked) { 
    $('.fileupload-buttonbar .toggle').first().trigger('click'); 
} 

//manually trigger the delete button for all files 
$('.fileupload-buttonbar .delete').first().trigger('click'); 

我知道這不是最好的方法。我知道這不是優雅的......但它適用於我,並從插件中刪除所有內容。

如果已經添加了文件名稱或任何從插件到任何本地數組或對象一樣,你需要手動清理這些了(我有幾個處理程序開火fileuploadaddedfileuploadsentfileuploadcompletefileuploadfailed,和' fileuploaddestroyed`事件)。

0
protected function get_file_objects($iteration_method = 'get_file_object') { 
    $upload_dir = $this->get_upload_path(); 
    if (!is_dir($upload_dir)) { 
     return array(); 
    } 
    return array_values(array_filter(array_map(
     array($this, $iteration_method) 
     //scandir($upload_dir) 
     //File listing closed by Doss 
    ))); 
} 

有一個scandir函數負責列出文件。就像我上面所做的那樣取消註釋,並且您的問題已解決。它可以在UploadHandler.php文件中找到。

+0

我全面搜索這個簡單的解決方案,在上傳後從屏幕上刪除圖像。爲什麼它在文檔中的任何地方都沒有提及,這是超越我的。這應該是#1解決方案,謝謝 – user1946891 2015-08-16 03:22:32