Search code examples
plupload

Allow user to upload only one file with Plupload


multi_selection=false limits user from selecting more than one file per once and max_file_size limits, how large file can be. But, is there anyway with Plupload to allow user to send only one file at all?

I only want to use Plupload as AJAX-uploader and reuse its chunking feature. I'm not interested at all in its ability to upload more than one file at once. I know, that I can block it (limit transfer to just one file) on server side, but this will happen after transmission has been made.

Is there any way to limit upload to just one file on client side, before any actually file transfer occurs?


Solution

  • The only solution, I came up with, is to use events, write your own code for QueueChanged event:

    QueueChanged: function(up) {
        function(uploader)
        {
            if(uploader.files.length > 1)
            {
                uploader.files.splice(1, uploader.files.length);
    
                apprise('You can not add more than one file!', {});
            }
        }
    }
    

    and put this into init section of Plupload Queue widget configuration (or bind this particular event with uploader.bind, if using simple, core UI version of Plupload).