Skip to content

Commit

Permalink
Gracefully return when file info or max size are not set.
Browse files Browse the repository at this point in the history
Remove default max limit - no size limit is assumed.
  • Loading branch information
protich committed Feb 28, 2013
1 parent 5839b54 commit 4356160
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions js/jquery.multifile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
Multifile plugin that allows users to upload multiple files at once in unobstructive manner - cleaner interface.
Allows limiting number of files and file type(s) using file extension.
Allows limiting number of files
Whitelist file type(s) using file extension
Limit file sizes.
NOTE:
* Files are not uploaded until the form is submitted
Expand Down Expand Up @@ -56,15 +58,13 @@
msg = 'File type of one or more of the selected files is NOT allowed';

alert('Error: '+msg);

$this.replaceWith(new_input);
} else if(!$.fn.multifile.checkFileSize(file, settings.max_file_size)) {
var msg = 'Selected file size is NOT allowed';
var msg = 'Selected file exceeds allowed size';
if(file.count>1)
msg = 'File size of one or more of the selected files is NOT allowed';
msg = 'File size of one or more of the selected files exceeds allowed size';

alert('Error: '+msg);

$this.replaceWith(new_input);
} else {
$this.hide();
Expand Down Expand Up @@ -137,6 +137,10 @@
};

$.fn.multifile.checkFileSize = function(file, MaxFileSize) {

//Size info not available or max file is not set (let server-side handle it).
if(!MaxFileSize || !file.size)
return true;

var filesizes = $.map(file.size.split(','), $.trim);
for (var i = 0, _len = filesizes.length; i < _len; i++)
Expand Down Expand Up @@ -176,6 +180,7 @@
// belong to only one file input. It is impossible
// to remove just one of the files.
file.name = input.files[0].name;
file.size = '' + input.files[0].size;
for (var i = 1, _len = input.files.length; i < _len; i++) {
file.name += ', ' + input.files[i].name;
file.size += ', ' + input.files[i].size;
Expand All @@ -194,6 +199,6 @@
$.fn.multifile.defaults = {
max_uploads: 1,
file_types: '.*',
max_file_size: 2048
max_file_size: 0
};
})(jQuery, this);
2 changes: 1 addition & 1 deletion js/osticket.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ $(document).ready(function(){
container: '.uploads',
max_uploads: ($config && $config.max_file_uploads)?$config.max_file_uploads:1,
file_types: ($config && $config.file_types)?$config.file_types:".*",
max_file_size: ($config && $config.max_file_size)?$config.max_file_size:2048
max_file_size: ($config && $config.max_file_size)?$config.max_file_size:0
});
});
2 changes: 1 addition & 1 deletion scp/js/scp.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ $(document).ready(function(){
container: '.uploads',
max_uploads: ($config && $config.max_file_uploads)?$config.max_file_uploads:1,
file_types: ($config && $config.file_types)?$config.file_types:".*",
max_file_size: ($config && $config.max_file_size)?$config.max_file_size:2048
max_file_size: ($config && $config.max_file_size)?$config.max_file_size:0
});

/* Datepicker */
Expand Down

0 comments on commit 4356160

Please sign in to comment.