Added pre-upload filesize check
authorAlexander Ebert <ebert@woltlab.com>
Thu, 27 Jun 2013 17:45:04 +0000 (19:45 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 27 Jun 2013 17:45:04 +0000 (19:45 +0200)
wcfsetup/install/files/js/WCF.Attachment.js
wcfsetup/install/files/js/WCF.js

index 167660212a1f93b10f027aba84e189656980f2e6..e558047b0a8b905101aa8f79c698a0164055140c 100644 (file)
@@ -140,10 +140,23 @@ WCF.Attachment.Upload = WCF.Upload.extend({
         * @see WCF.Upload._initFile()
         */
        _initFile: function(file) {
-               var $li = $('<li class="box48"><span class="icon icon48 icon-spinner" /><div><div><p>'+file.name+'</p><small><progress max="100"></progress></small></div><ul></ul></div></li>');
+               var $li = $('<li class="box48"><span class="icon icon48 icon-spinner" /><div><div><p>'+file.name+'</p><small><progress max="100"></progress></small></div><ul></ul></div></li>').data('filename', file.name);
                this._fileListSelector.append($li);
                this._fileListSelector.show();
                
+               // validate file size
+               if (this._buttonSelector.data('maxSize') < file.size) {
+                       // remove progress bar
+                       $li.find('progress').remove();
+                       
+                       // upload icon
+                       $li.children('.icon-spinner').removeClass('icon-spinner').addClass('icon-ban-circle');
+                       
+                       // error message
+                       $li.find('div > div').append($('<small class="innerError">' + WCF.Language.get('wcf.attachment.upload.error.tooLarge') + '</small>'));
+                       $li.addClass('uploadFailed');
+               }
+               
                return $li;
        },
        
index 530f027c2f9081e259d521617a8549de8dbeb3b1..6dcd97b64e39b7f61cf91694dfc40d24446914b5 100755 (executable)
@@ -6578,8 +6578,23 @@ WCF.Upload = Class.extend({
                        var $fd = new FormData();
                        var $uploadID = this._createUploadMatrix($files);
                        
+                       // no more files left, abort
+                       if (!this._uploadMatrix[$uploadID].length) {
+                               return;
+                       }
+                       
+                       var $validFilenames = [ ];
+                       for (var $i = 0, $length = this._uploadMatrix[$uploadID].length; $i < $length; $i++) {
+                               var $li = this._uploadMatrix[$uploadID][$i];
+                               if (!$li.hasClass('uploadFailed')) {
+                                       $validFilenames.push($li.data('filename'));
+                               }
+                       }
+                       
                        for (var $i = 0, $length = $files.length; $i < $length; $i++) {
-                               $fd.append('__files[]', $files[$i]);
+                               if ($validFilenames.indexOf($files[$i].name) !== -1) {
+                                       $fd.append('__files[]', $files[$i]);
+                               }
                        }
                        
                        $fd.append('actionName', this._options.action);
@@ -6629,8 +6644,10 @@ WCF.Upload = Class.extend({
                                var $file = files[$i];
                                var $li = this._initFile($file);
                                
-                               $li.data('filename', $file.name);
-                               this._uploadMatrix[$uploadID].push($li);
+                               if (!$li.hasClass('uploadFailed')) {
+                                       $li.data('filename', $file.name);
+                                       this._uploadMatrix[$uploadID].push($li);
+                               }
                        }
                        
                        return $uploadID;