這應該會包含在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);