From 404c9f0da3941d28bb752f47f74021cbdc3b1d1b Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 27 Jun 2013 19:45:04 +0200 Subject: [PATCH] Added pre-upload filesize check --- wcfsetup/install/files/js/WCF.Attachment.js | 15 +++++++++++++- wcfsetup/install/files/js/WCF.js | 23 ++++++++++++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.Attachment.js b/wcfsetup/install/files/js/WCF.Attachment.js index 167660212a..e558047b0a 100644 --- a/wcfsetup/install/files/js/WCF.Attachment.js +++ b/wcfsetup/install/files/js/WCF.Attachment.js @@ -140,10 +140,23 @@ WCF.Attachment.Upload = WCF.Upload.extend({ * @see WCF.Upload._initFile() */ _initFile: function(file) { - var $li = $('
  • '+file.name+'

    • '); + var $li = $('
    • '+file.name+'

      • ').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($('' + WCF.Language.get('wcf.attachment.upload.error.tooLarge') + '')); + $li.addClass('uploadFailed'); + } + return $li; }, diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 530f027c2f..6dcd97b64e 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -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; -- 2.20.1