我有<input type="file" name="attach" multiple>
,我需要使用這個倍數的倍數。我的意思是什麼,我需要什麼:如何使用輸入文件兩次
- 首先點擊我選擇2個文件:
file1.png
file2.png
- 第二次點擊我選擇3個文件:
file3.png
file4.png
file5.png
,我需要5個文件。
但是當我做第二次點擊我剛剛過去的3
我有<input type="file" name="attach" multiple>
,我需要使用這個倍數的倍數。我的意思是什麼,我需要什麼:如何使用輸入文件兩次
file1.png
file2.png
file3.png
file4.png
file5.png
,我需要5個文件。
但是當我做第二次點擊我剛剛過去的3
一個我的方法,我可以建議是,當用戶選擇文件,您可以用新的具有相同名稱的屬性將取代前面的<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
我需要作爲電子郵件附件,所以dropzone不好。我不需要將它保存在服務器上。 如果我將有大量的輸入,它會在'$ _FILES'中有用嗎? – GoogleParamoik
試試上面的腳本,多個文件應該在$ _FILES中可見 –
@GoogleParamoik它適用於你嗎? –
可能這http://stackoverflow.com/questions/3654179/retrieving-file-names-out-of-a-multi-file-upload-control-with-javascript – Ashan
你爲什麼不選擇5文件一次,並在服務器端相應地使用它們 –
@SunilPachlangia我會,但我的客戶沒有.. – GoogleParamoik