Re: [請益] file[]重複選取

作者: hareion08 (巨蟹)   2015-04-27 10:40:53
不知道你說的是不是這樣,小試了一下
<script language="javascript">
function insertFile(th)
{
var nf = document.createElement("input");
nf.type = "file";
nf.name = "files[]";
nf.files = th.files;
nf.style.display = "none";
document.getElementById("form1").appendChild(nf);
}
</script>
<form method="post" action="?do=upload" enctype="multipart/form-data"
id="form1">
<input type="file" name="files[]" onchange="insertFile(this)"
multiple="multiple" />
<input type="submit"/>
</form>
<?php
if($_GET['do']=="upload")
{
?>
<pre>
<?=var_dump($_FILES['files']);?>
</pre>
<?php
}
?>
每選擇完一次檔案就偷塞一個input file到表單,設置一樣的欄位名稱
沒有誤會你意思的話 已測試應該沒錯~
每次選擇的檔案都會留下
算是硬幹的方法,但試過其他方式無法達成
細節的部分(重複篩選)就比較做不出來
不然就要從後端判斷
作者: xdraculax (首席怪叔叔)   2015-04-28 02:55:00
好久不見的原生js
作者: gname ((′口‵)↗︴<><...<><)   2015-04-28 08:18:00
原生才是王道!
作者: hareion08 (巨蟹)   2015-04-28 09:24:00
原生才是王道!,我懶的引用Jquery 哈哈
作者: MOONRAKER (㊣牛鶴鰻毛人)   2015-04-28 09:54:00
原生DOM煩死了 不得已要用一定自己把他包裝過function $i(c){return document.getElementById(c)}這樣
作者: mmis1000 (秋月戀楓)   2015-04-28 12:21:00
不考慮ie的話,原生其實還好啦...ie一堆跟w3c spec不一樣,不用jquery根本噴到死
作者: pate123 (笨蛋)   2015-05-04 21:30:00
感謝h大,不過我需要每個瀏覽器都能夠跑得動

Links booklink

Contact Us: admin [ a t ] ucptt.com