2014-01-25 46 views
0

下降当我尝试使用下面的函数来获取所有文件的相对路径,获取所有文件的relativePath当文件夹拖放在Plupload

uploader.bind('FilesAdded', function(up, files) { 
    plupload.each(files,function(file) { 
     console.log('Relative path: ' + file.relativePath) 
    }) 
}); 

它记录为Relative Path: undefined

任何线索如何解决这个问题?

回答

0

这应该会包含在plupload的下一个版本(2.1.3)中。直到新的版本出来你可能想使用此解决方法:

(来源:http://www.i-do-this.com/blog/plupload-2-1-chrome-and-folder-support/57

var uploader, traverseFileTree, map = {}; 

// replace by your plupload setup, this is just an example 
uploader = new plupload.Uploader({ 
    runtimes : 'html5', 
    container: 'drop-target', 
    drop_element: 'drop-target', 
    browse_button : 'files', 
    url : 'http://www.torrentplease.com/dropzone.php', 
    init: { 
     PostInit: function() { 
      document.getElementById('uploadfiles').onclick = function() { 
       uploader.start(); 
       return false; 
      }; 
     }, 
     BeforeUpload: function (up, file) { 
      // send relativePath along 
      if(map[file.name] !== undefined) { 
       up.setOption('multipart_params', { 
        relativePath: map[file.name].shift() 
       }); 
      } 
     } 
    } 
}); 
uploader.init(); 

// all relative paths are built here 
traverseFileTree = function (item, path) { 
var dirReader = null; 
    path = path || ''; 
    if (item.isFile) { 
     item.file(function(file) { 
      // careful here, could be several files of the same name 
      // we assume files will be in the same order here than in plupload 
      if(map[file.name] === undefined) { 
       map[file.name] = []; 
      } 
      map[file.name].push(path); 
     }); 
    } else if (item.isDirectory) { 
     dirReader = item.createReader(); 
     dirReader.readEntries(function (entries) { 
      var n = 0; 
      for (n = 0; n < entries.length; n++) { 
       traverseFileTree(entries[n], path + item.name + "/"); 
      } 
     }); 
    } 
}; 

// bind another handler to the drop event to build an object representing the folder structure 
document.getElementById('drop-target').addEventListener('drop', function(e) { 
    var items = e.dataTransfer.items, n, item; 
    for(n = 0; n < items.length; n++) { 
     item = items[n].webkitGetAsEntry(); 
     if(item) { 
      traverseFileTree(item); 
     } 
    } 
}, false); 
相关问题