We have a form element that allows the user to “scoop” files in bulk, rather than clicking on one. It is implied that the files are immediately sent to the server as soon as they are selected (because I don’t see much point in forming a list, and then submit again)
<input type="file" multiple="multiple" name="files[]" />
However, if we want to restrict a user, for example, with a portion of 10 files (say, not to overload the server, or if, say, we have a policy of 10 files on one site in one hand), here we are in for a slight disappointment. Or great.
In HTML5, this feature is not implemented (or I do not know about it). We can specify the minimum number of files (that is, one minimum), but the maximum alas.
Get the number of files is not difficult. But then what to do with it?
var collect = document.getElementById('input').files; //или var collect = $("input").files; // вернет объект FileList : { 0, 1, 2, length: 3, item }
Options:
- give a message to the user that he has exceeded the chunk limit and interrupt the download;
- download a valid portion and give a message that only part of the files have been downloaded;
- create a residue "for later";
- create a common list, prompting the user to form a batch;
In addition to these torments, we have a purely technical question: how to cut the files array?
The splice()
method is not understood. delete collect.item(i) или delete collect[i]
has no effect on it, it does not want to turn into null
. I also failed to create one more input (or series) and "download" the limited number of files into it.
That is, there is only one option: to rudely interrupt the download, forcing the user to reassemble the collection.