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.