作者hareion08 (巨蟹)
看板PHP
標題Re: [請益] file[]重複選取
時間Mon Apr 27 10:40:53 2015
不知道你說的是不是這樣,小試了一下
<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到表單,設置一樣的欄位名稱
沒有誤會你意思的話 已測試應該沒錯~
每次選擇的檔案都會留下
算是硬幹的方法,但試過其他方式無法達成
細節的部分(重複篩選)就比較做不出來
不然就要從後端判斷
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.50.144
※ 文章網址: https://webptt.com/m.aspx?n=bbs/PHP/M.1430102456.A.31A.html
1F:推 xdraculax: 好久不見的原生js 04/28 02:55
2F:→ gname: 原生才是王道! 04/28 08:18
3F:→ hareion08: 原生才是王道!,我懶的引用Jquery 哈哈 04/28 09:24
4F:→ MOONRAKER: 原生DOM煩死了 不得已要用一定自己把他包裝過 04/28 09:54
5F:→ MOONRAKER: function $i(c){return document.getElementById(c)} 04/28 09:55
6F:→ MOONRAKER: 這樣 04/28 09:55
7F:→ mmis1000: 不考慮ie的話,原生其實還好啦...ie一堆跟w3c spec 04/28 12:21
8F:→ mmis1000: 不一樣,不用jquery根本噴到死 04/28 12:21
9F:→ pate123: 感謝h大,不過我需要每個瀏覽器都能夠跑得動 05/04 21:30