我使用此插件上传多文件fyneworks。我的问题是这样的:
- Select one or more e:g 2 files on browse button, then I get those files
- I clicked again, and choose a lot of file e/g 1 file, on preview I got three.
- But when uploaaded, I just got the two image which is the first select.
这是我的代码: 我有一个div来显示菜单上传,如下所示:
$(document).on("click", '#menu_container', function () {
var this_url = $(this).attr("href");
$.post(this_url, {}, function (data) {
$('#content').html(data);
$('#file').addClass("multi with-preview");
$('#file').MultiFile({
list: "#log",
max: 10,
accept: 'jpg|png|gif|jpeg',
STRING: {
file: '<p>$file</p>',
remove: '<button type="button" class="btn btn-sm btn-danger">Hapus </button>'
}
});
});
return false;
});
现在,这是html页面:
<?php echo form_open_multipart('', array('id' => 'upload', 'enctype' => "multipart/form-data")); ?>
<div class="form-group col-sm-12 ">
<label for="file">Upload Foto</label>
<input name="file[]" id="file" class=" btn" type="file" multiple >
<div class="col-sm-6" id="log"> </div>
</div>
<button type="submit" class="btn btn-primary btn-block">Submit</button>
<?php echo form_close(); ?>
我使用ajax提交这样的照片:
$('#upload').submit(function () {
$.blockUI();
var form = $('#upload');
var inputFile = $('input#file');
var filesToUpload = inputFile[0].files;
// make sure there is file(s) to upload
if (filesToUpload.length > 0) {
// provide the form data that would be sent to sever through ajax
var formData = new FormData();
for (var i = 0; i < filesToUpload.length; i++) {
var file = filesToUpload[i];
formData.append("file[]", file, file.name);
}
$.ajax({
url: "<?php echo base_url('surveyor/c_surveyor/add_file_image/'); ?>/" + response.Nama_file + response.No_inspection,
type: 'post',
data: formData,
processData: false,
contentType: false,
success: function (obj) {
$.unblockUI();
$(":file").val('');
$(":text").val('');
$("#comments").val('');
$(".MultiFile-label").empty();
$('#pilih_isotank').before('<div class="callout callout-success lead" id="div_error"><p id="pesan_error">Data Berhasil Terupload dengan Nomor : ' + response.No_inspection + '</p></div>');
$('#pilih_isotank').after('<div class="callout callout-success lead" id="div_error"><p id="pesan_error">Data Berhasil Terupload dengan Nomor : ' + response.No_inspection + '</p></div>');
$('#div_error').fadeIn("fast");
$('#pesan_error').html(obj.Message);
$('#div_error').fadeOut(7000);
$('input:file').MultiFile('reset');
console.log("Update succcess");
},
error: function () {
alert('Ada yang salah, press ctrl + r');
}
});
} else {
$('#file').after('<div class="callout callout-danger lead" id="div_error"><p id="pesan_error"></p></div>');
$('#div_error').fadeIn("fast");
$('#pesan_error').html("Please Choose your Photo...");
$('#div_error').fadeOut(7000);
$.unblockUI();
}
return false;
});
我已阅读过doc:有事件:
onFileAppend
afterFileAppend
onFileSelect
afterFileSelect
onFileRemove
afterFileRemove
我该怎么办。任何帮助它如此欣赏。