jQuery Plupload restrict number of uploads

前端 未结 2 1053
再見小時候
再見小時候 2020-12-06 02:43

I have been working on this code for some time now trying to get it to work properly. I want to restrict the use from uploading more that 2 images in total.

The li

2条回答
  •  再見小時候
    2020-12-06 03:10

    Good answer jbl. I tweaked your solution a bit to make it more generic, and to make the 'Add files' button reappear when needed.

    uploader.bind('FilesAdded', function(up, files) {
      if (up.files.length >= up.settings.max_files) {
        up.splice(up.settings.max_files);
        $(up.settings.browse_button).hide();
      }
    });
    
    uploader.bind('FilesRemoved', function(up, files) {
      if (up.files.length < up.settings.max_files) {
        $(up.settings.browse_button).show();
      }
    });
    

    max_files is part of the pluploadQueue settings

    $("#uploadBox").pluploadQueue({
      ...
      max_files: 2,
      ...
    });
    

提交回复
热议问题