Valums ajax upload script is a very nice, clean, and simple to integrate script for uploading files synchronously with ajax (and if it’s not supported in your browser iframes). It’s simply the best implementation I’ve seen, except for one minor glitch.
If you tell it to not allow multiple synchronous file uploads (instead allowing one at a time) it still allows you to drag and drop more than one file at a time, until now. Earlier today at work I programmed in a fix (along with some other modifications to the naming and saving and layout system) that will throw up a message when you try and drop more than 1 file at a time.
The solution is below, note that it starta at line 574
1 2 3 4 5 6 7 8 9 |
var key; var cnt=-2; // Not sure why it's always adding 2 but it _always_ is. for (key in e.dataTransfer.files) { cnt++; } if(self._options.multiple==false && cnt>1){ self._options.showMessage('You may only upload 1 file at the site, please deselect '+(cnt-1)+' images and try again.'); }else{ self._uploadFileList(e.dataTransfer.files); } |
Snipplr: http://snipplr.com/view/50846/valums-ajax-file-upload-single-item-fix/
The key is to replace the line “self._uploadFileList(e.dataTransfer.files);” (originally at line 577) with that simple for and if statement that checks if they have multiple uploads disabled, and if they do and there trying to upload multi files, throws an error message. Pretty simple but I figured I’d post it so nobody else has to fig through the code to find it.
Hi, I was wondering if you knew how to configure Valums upload so as to allow for only 3 files to be uploaded. Thanks
James
It’s has no method set up to do that, and the dialog that comes up when you press the button cannot be controlled (as in, they can always select more than 3 files or 1 file, you can’t change that) but the code above can be modified to only allow 3 items to be dropped on it. I guess the question is 3 at a time or 3 total, because I don’t know how you would limit it to 3 total (well I do, modify the php upload script to store the information somewhere (say, the session variable) and then count it off, after three have the upload script always send an error back and refuse to upload).
Thanks for this, just what I was looking for