Skip to content

Instantly share code, notes, and snippets.

@yasaryousuf
Created June 4, 2018 08:51
Show Gist options
  • Save yasaryousuf/8c7ae1ad182586f0693a85624b0f658a to your computer and use it in GitHub Desktop.
Save yasaryousuf/8c7ae1ad182586f0693a85624b0f658a to your computer and use it in GitHub Desktop.
$('.doc input').fileupload(
{
url: WP_Ajax.ajaxurl,
sequentialUploads: true,
formData: {action: 'upload_file'},
add: function (e, data) {
var uploadErrors = [];
var acceptFileTypes = /\/(pdf|JPEG|JPG|TIFF|GIF|png|BMP|DOC|DOCX|XLS|XLSX|ODT|ODS)$/i;
if(data.originalFiles[0]['type'].length && !acceptFileTypes.test(data.originalFiles[0]['type'])) {
uploadErrors.push('File type not accepted');
}
if (data.originalFiles[0]['size'] > 10000000) {
uploadErrors.push('Filesize too big. Maximum file size should be 10 MB');
}
if(uploadErrors.length > 0) {
swal("", uploadErrors.join("\n"), "error");
} else {
data.context = $('<p/>').text('Uploading...').appendTo(document.body);
data.submit();
}
},
done: function(e, data){
var html = data.result + '<a class="remove-file"><i class="fa fa-minus-circle"></i></a>';
$(e.target).closest('.doc').find('.file-name').html(html);
documentProgress();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment