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

看板PHP作者 (巨蟹)時間10年前 (2015/04/27 10:40), 編輯推噓1(108)
留言9則, 6人參與, 最新討論串2/2 (看更多)
不知道你說的是不是這樣,小試了一下 <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://www.ptt.cc/bbs/PHP/M.1430102456.A.31A.html

04/28 02:55, , 1F
好久不見的原生js
04/28 02:55, 1F

04/28 08:18, , 2F
原生才是王道!
04/28 08:18, 2F

04/28 09:24, , 3F
原生才是王道!,我懶的引用Jquery 哈哈
04/28 09:24, 3F

04/28 09:54, , 4F
原生DOM煩死了 不得已要用一定自己把他包裝過
04/28 09:54, 4F

04/28 09:55, , 5F
function $i(c){return document.getElementById(c)}
04/28 09:55, 5F

04/28 09:55, , 6F
這樣
04/28 09:55, 6F

04/28 12:21, , 7F
不考慮ie的話,原生其實還好啦...ie一堆跟w3c spec
04/28 12:21, 7F

04/28 12:21, , 8F
不一樣,不用jquery根本噴到死
04/28 12:21, 8F

05/04 21:30, , 9F
感謝h大,不過我需要每個瀏覽器都能夠跑得動
05/04 21:30, 9F
文章代碼(AID): #1LFQ6uCQ (PHP)
文章代碼(AID): #1LFQ6uCQ (PHP)