1. 程式人生 > >input 選取資料夾及多個檔案 識別內部檔案

input 選取資料夾及多個檔案 識別內部檔案

input 選取資料夾

  • input 檔案的選取
    <input type="file" class="upfile" multiple="multiple"  /> 可以選取多個檔案
    <input type="file" class="upfile" webkitdirectory /> 可以選擇一個資料夾
  • 拾取內部檔案
    change 事件
 $fileInput.off().one('change', function (e) {
            var  files=e.target.files;
            [].forEach.call(files,function
(item){
if(item) { uploading(item); //上傳資料夾 } },false/true); this.value=''; }); $fileInput.click();
  • 內部 fileList
    在 e.target.files 中 但其中列表 陣列形式 ,並不能識別目錄結構

  • 強大的webkitRelativePath

    內部檔案的路徑


 function uploading
(file){
if(/^\..*/.test(file.name))return // 隱藏檔案 取消 var arrpaths= file.webkitRelativePath.split('/'); arrpaths.pop(file.webkitRelativePath); }