aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/assets
diff options
context:
space:
mode:
authormrgoldy <gijsmartens1@gmail.com>2019-08-25 21:24:22 +0200
committermrgoldy <gijsmartens1@gmail.com>2019-08-25 21:24:22 +0200
commit8bc056ebe6d5876c6de2a2ca84bf234678c3e702 (patch)
tree2dcd7bd57b28c17866edfc0577dbe058240feb9c /phpBB/assets
parent9c15594fe498a8a1640bb89aa0c93800918a9798 (diff)
downloadforums-8bc056ebe6d5876c6de2a2ca84bf234678c3e702.tar
forums-8bc056ebe6d5876c6de2a2ca84bf234678c3e702.tar.gz
forums-8bc056ebe6d5876c6de2a2ca84bf234678c3e702.tar.bz2
forums-8bc056ebe6d5876c6de2a2ca84bf234678c3e702.tar.xz
forums-8bc056ebe6d5876c6de2a2ca84bf234678c3e702.zip
[ticket/16076] addFileFilter to check max file size per mime type
PHPBB3-16076
Diffstat (limited to 'phpBB/assets')
-rw-r--r--phpBB/assets/javascript/plupload.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/phpBB/assets/javascript/plupload.js b/phpBB/assets/javascript/plupload.js
index fab1ca6d7c..ab6d0d7e88 100644
--- a/phpBB/assets/javascript/plupload.js
+++ b/phpBB/assets/javascript/plupload.js
@@ -446,6 +446,44 @@ phpbb.plupload.fileError = function(file, error) {
phpbb.plupload.uploader = new plupload.Uploader(phpbb.plupload.config);
phpbb.plupload.initialize();
+/**
+ * Add a file filter to check for max file sizes per mime type.
+ */
+plupload.addFileFilter('mime_types_max_file_size', function(types, file, cb) {
+ if (file.size !== 'undefined') {
+ $(types).each(function(i, type) {
+ let extensions = [],
+ exts_array = type.extensions.split(',');
+
+ $(exts_array).each(function(i, extension) {
+ /^\s*\*\s*$/.test(extension) ? extensions.push("\\.*") : extensions.push("\\." + extension.replace(new RegExp("[" + "/^$.*+?|()[]{}\\".replace(/./g, "\\$&") + "]", "g"), "\\$&"));
+ });
+
+ let regex = new RegExp("(" + extensions.join("|") + ")$", "i");
+
+ if (regex.test(file.name)) {
+ if (type.max_file_size !== 'undefined' && type.max_file_size) {
+ if (file.size > type.max_file_size) {
+ phpbb.plupload.uploader.trigger('Error', {
+ code: plupload.FILE_SIZE_ERROR,
+ message: plupload.translate('File size error.'),
+ file: file
+ });
+
+ cb(false);
+ } else {
+ cb(true);
+ }
+ } else {
+ cb(true);
+ }
+
+ return false;
+ }
+ });
+ }
+});
+
var $fileList = $('#file-list');
/**