2016-03-07 51 views
1

我有<input type="file" name="attach" multiple>,我需要使用这个倍数的倍数。我的意思是什么,我需要什么:如何使用输入文件两次

  1. 首先点击我选择2个文件:

file1.png

file2.png

  • 第二次点击我选择3个文件:
  • file3.png

    file4.png

    file5.png

    ,我需要5个文件。

    但是当我做第二次点击我刚刚过去的3

    +1

    可能这http://stackoverflow.com/questions/3654179/retrieving-file-names-out-of-a-multi-file-upload-control-with-javascript – Ashan

    +0

    你为什么不选择5文件一次,并在服务器端相应地使用它们 –

    +0

    @SunilPachlangia我会,但我的客户没有.. – GoogleParamoik

    回答

    0

    一个我的方法,我可以建议是,当用户选择文件,您可以用新的具有相同名称的属性将取代前面的<input type="file"....>

    现在用户将再次选择几个文件并提交。您将在服务器端获得多个文件,因为两个输入元素的name属性都相同。

    <div id="parent"> 
        <input type="file" name="attach[]" onchange="append_new_input_element(this)" multiple> 
    </div> 
    

    添加下面的函数

    function append_new_input_element(this){ 
    parent_div = document.getElementById("parent"); 
    this.style.display = "none"; 
    var input = document.createElement("input"); 
    input.type = "file"; 
    input.name = "attach[]";    
    
    input.setAttribute("onchange","append_new_input_element(this)");    
    parent_div.appendChild(input); 
    
    } 
    

    否则我会建议使用悬浮窗用于此目的。 dropzone

    +0

    我需要作为电子邮件附件,所以dropzone不好。我不需要将它保存在服务器上。 如果我将有大量的输入,它会在'$ _FILES'中有用吗? – GoogleParamoik

    +0

    试试上面的脚本,多个文件应该在$ _FILES中可见 –

    +0

    @GoogleParamoik它适用于你吗? –