, Bootstrap File Input . , Javascript!
, fileuploaderror (, ). , , . ). msgSizeTooLarge , . msgSizeTooLarge ; {size} {customSize}, {maxSize} {customMaxSize}. msgSizeTooLarge :
msgSizeTooLarge: 'File "{name}" (<b>{customSize}</b>) exceeds maximum allowed upload size of <b>{customMaxSize}</b>. Please retry your upload!'
, data, fileuploaderror, size = data.files[0].size. maxFileSize , filenputs maxFileSize = $(this).data().fileinput.maxFileSize. , MB . formatSize wil :
formatSize = (s) => {
i = Math.floor(Math.log(s) / Math.log(1024));
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
out = (s / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + sizes[i];
return out;
};
replace :
msg = msg.replace('{customSize}', formatSize(size));
msg = msg.replace('{customMaxSize}', formatSize(maxFileSize * 1024 ));
:
"Endless Dream.mp3" (2.07 ) 2 . !
, data.id, <li> , :
$('li[data-file-id="'+data.id+'"]').html(msg);
:

. 2 .
javascript
$("#file-1").fileinput({
uploadUrl: '#',
overwriteInitial: false,
maxFileSize: 2048,
msgSizeTooLarge: 'File "{name}" (<b>{customSize}</b>) exceeds maximum allowed upload size of <b>{customMaxSize}</b>. Please retry your upload!'
}).on('fileuploaderror', function(event, data, msg) {
var size = data.files[0].size,
maxFileSize = $(this).data().fileinput.maxFileSize,
formatSize = (s) => {
i = Math.floor(Math.log(s) / Math.log(1024));
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
out = (s / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + sizes[i];
return out;
};
msg = msg.replace('{customSize}', formatSize(size));
msg = msg.replace('{customMaxSize}', formatSize(maxFileSize * 1024 ));
$('li[data-file-id="'+data.id+'"]').html(msg);
});