From: Alexander Ebert Date: Thu, 27 Jun 2013 17:45:04 +0000 (+0200) Subject: Added pre-upload filesize check X-Git-Tag: 2.0.0_Beta_5~118^2~19 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=404c9f0da3941d28bb752f47f74021cbdc3b1d1b;p=GitHub%2FWoltLab%2FWCF.git Added pre-upload filesize check --- 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;