我已经写了正常的多文件拖放上传器,
HTML:
<div class="drop-box drop-area">
<form enctype="multipart/form-data" id="yourregularuploadformId">
<input type="file" name="files[]" multiple="multiple" class="hidden">
</form>
</div>
SCRIPT:
$('.drop-area').on(
'drop',
function (e) {
e.preventDefault();
e.stopPropagation();
if (e.originalEvent.dataTransfer) {
if (e.originalEvent.dataTransfer.files.length) {
processFileUpload(e.originalEvent.dataTransfer.files);
}
}
}
);
function processFileUpload(droppedFiles) {
var uploadFormData = new FormData($("#yourregularuploadformId")[0]);
if (droppedFiles.length > 0) {
for (var f = 0; f < droppedFiles.length; f++) {
uploadFormData.append("files[]", droppedFiles[f]);
}
}
$.ajax({
url: "files.php",
type: "POST",
data: uploadFormData,
cache: false,
contentType: false,
processData: false,
success: function (ret) {
alert("file uploaded !");
},
});
}
我必须上传文件夹,嵌套文件夹(dir)。这该怎么做 ?任何人都有这个。它是可能的。我不需要使用库来做这件事。 (它必须适用于IE10)