Search code examples
javascriptjqueryjquery-file-upload

jquery file upload alert on maxNumberOfFiles


I am using jQuery File Upload plugin (http://blueimp.github.io/jQuery-File-Upload/) for image upload for my website.

My Code:

$('#fileupload').fileupload({
    url: 'server/index.php',
    dataType: 'json',
    dropZone: $('#dropzone'),
    disableImageResize: false,
    imageMaxWidth: 800,
    imageMaxHeight: 800,
    acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
    maxNumberOfFiles:3,
    singleFileUploads: false,
});

When user try to upload more than 3 files, the script does prevent files from being uploaded. But it doesn't do anything or show anything to tell user that their files is over limit.

So, how can I have the plugin to display an alert box when user try to upload files more than maximum number allowed?

Thank you.


Solution

  • Well, I guess there is no direct way. You have to program it manually yourself.

    ('#fileupload').fileupload({
     ....
    }).on('fileuploadadd', function (e, data) {
    //program your logic here
    filenum = data.files.length;
    ...
    });