2012-06-13 102 views
1

我已經發布了similar question,但沒有找到任何合適的解決方案。輸入多個文件並將它們分離爲單獨的表格

我已經簡化了要求:

  1. 能力,讓用戶選擇多個文件
  2. 從選定的文件,將每個文件在一個單獨的形式
  3. 分別提交每個窗體

我努力實現第二步。任何幫助都會很棒。所有想法都歡迎。

+0

如果我們能夠將文件從另一個問題中分離出來,那麼在這裏也可以這樣做。請不要發佈重複:) –

+0

猜你需要避免提交表格和使用Ajax,因爲出於安全原因,文件輸入不能由JavaScript設置。爲此,您可能會使用File API。 – Prusse

+0

@Scott S - 目標是將該文件分割並保存在表單中,直到用戶僅提交特定表單,而目前我無法做到這一點。 – user1450322

回答

0

在一些行的事...

HTML:

<input type="file" multiple onchange="handleFiles(this.files)"> 

的JavaScript:

function handleFiles(files){ 
    //create/associates a form with each file ("files.length" files) 
    // ... do stuff ... 
} 

function doAllSubmits(){ 
    // for each form call "doAsubmit" 
} 

function doASubmit(some_id, callback){ 
    // instantiate a XmlHttpRequest 
    // (or use jquery or any other library you're using) 
    // use a POST method 
    // (if I remember GET has(may have) query size limitations) 
    // populate with the form data 
    // plus the respective file data 
    // (maybe with readAsDataURL) 
} 

一些例子使用的組件引用:

Using_files_from_web_applications(MDN)

DOM/FileReader(MDN)

相關問題