1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
$('#file-img').fileupload({
dataType: 'json',
autoUpload: false,
formData: {type: 'business', proposal: 'demand'},
add: function (e, data) {
var uploadErrors = [];
var acceptFileTypes = /^image\/(gif|jpe?g|png)$/i;
if(data.originalFiles[0]['type'] && !acceptFileTypes.test(data.originalFiles[0]['type'])) {
uploadErrors.push('Not an accepted file type');
}
if(data.originalFiles[0]['size'] && data.originalFiles[0]['size'] > 4000000) {
uploadErrors.push('File size is too big');
}
if(uploadErrors.length > 0) {
alert(uploadErrors.join("\n"));
} else {
$.each(data.files, function (index, file) {
$("#txt-file-img").val(file.name);
});
$("#btn_add_valid").on('click',function () {
$("#loading_img_modal").modal("show");
data.submit();
});
}
},
done: function (e, data) {
$("#loading_img_modal").modal("hide");
},
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#upload-img .bar').css(
'width',
progress + '%'
);
$('#img-percentage').text(
progress + '%'
);
},
fail: function (e, data) {
alert('Error');
$("#loading_img_modal").modal("hide");
}
}); |
Partager