2015-07-20 83 views
0

有沒有可能通過將URL傳遞給FileReader方法來上傳文件? 問題是,我有文檔放在兩個頁面 - 正面和背面(或側面 - A和B面 - sasb),在圖像中掃描,命名爲0001sa.jpg,0001sb.jpg等。我必須在瀏覽器中可視化它們的一部分,並在稍後將其URL-s放入數據庫中。jquery同時上傳兩個文件

如果用戶標誌着這兩個文件,很容易:

function readURL(input) { 
    if (input.files && input.files[0]) { 

     filelst = input.files;   
     $("#pict_name").val(filelst[0].name); 

     var reader = new FileReader(); 

     reader.onload = function (e) {    
      $('#imgPrev').attr('src', e.target.result).css('max-width', '2200px'); 
      $('#imgPrev').attr('data-zoom-image', e.target.result); 
     // imgPrev is the ID of the div, where I place the preview 
     // of part the image 
     } 

     reader.readAsDataURL(input.files[0]); 

     var reader_b = new FileReader(); 
     reader_b.onload = function (eb) { 
      $('#imgPrev1').attr('src', eb.target.result).css('max-width', '2100px'); 
      $('#imgPrev1').attr('data-zoom-image', eb.target.result); 
      //I have to visualize different part of the back of the document 
     } 
     reader_b.readAsDataURL(input.files[1]); 

    } 
} 

但是,兩個文件點擊是不是方便了運營商和 易患錯誤。如果我可以使用後面的URL來上傳它,甚至可以將文件分隔在不同的目錄中。 何我可以做到這一點,或者是FileReader在這種情況下不是正確的方法?

回答

0

您可以使用Ajax上傳多個文件。嘗試使用jQuery上傳ajax文件。也有許多基於jQuery的上傳者可用。