$(document).ready(function() { var $limit_message = '
NOTE: The maximum allowed total uploaded file size per form submission is 10MB.
EXAMPLE: Your upload limit is 8MB. If you upload 5 images that are 1.5MB each (7.5MB total), the form submission will be successful, but if you upload 5 images that are 3MB each (15MB total), it will fail.
'; var $file_error_div = '
'; $($limit_message).insertBefore('.file-upload-form'); $($file_error_div).insertBefore('.file-upload-form'); $( '' ).insertBefore( ".FileToUpload" ); $(".clear-input").css( {"display" : "block","float" : "right"}); $(".FileToUpload").on( "click change", (function() { checkFileSizes(); }) ); $(".clear-input").click(function() { var curIndex = $( ".clear-input" ).index( this ); //alert("The index is " + curIndex); //$('.FileToUpload').eq(curIndex).css( {"background-color" : "#0000FF"}); $('.FileToUpload').eq(curIndex).val(""); $('.FileToUpload').eq(curIndex).clone().insertBefore( $('.clear-input').eq(curIndex) ); $('.FileToUpload').eq(curIndex).remove(); checkFileSizes(); //$( '' ).insertBefore( $('.clear-input').eq(curIndex) ); }); function checkFileSizes() { //alert("Checking file sizes"); $("#file-upload-message").css( {"display" : "none"}); $(".file-upload-form input[type=submit]").prop( "disabled", false); //$(".clear-input").css( {"display" : "none"}); var TotalSize = 0; $( ".FileToUpload" ).each(function( index ) { var curFile; var curSize; var curSizeMB; var curSizeGB; var formattedSize; if(this.files[0]) { curFile = this.files[0]; curSize = curFile.size; // size in bytes curSizeKB = curSize / 1024; curSizeMB = curSizeKB / 1024; curSizeGB = curSizeMB / 1024; TotalSize += curSize; if(curSize > 1) { formattedSize = curSize.toFixed(2) + " Bytes"; //alert(formattedSize); } if(curSizeKB > 1) { formattedSize = curSizeKB.toFixed(2) + "KB"; //alert(formattedSize); } if(curSizeMB > 1) { formattedSize = curSizeMB.toFixed(2) + "MB"; //alert(formattedSize); } if(curSizeGB > 1) { formattedSize = curSizeGB.toFixed(2) + "GB"; //alert(formattedSize); } // formattedSize = (Math.round(curSize * 100) / 100) //alert(formattedSize); //alert(curFile.size||curFile.fileSize); //alert("Current file size is " + curSize); } }); // Get formatted File Size Total TotalSizeKB = TotalSize / 1024; TotalSizeMB = TotalSizeKB / 1024; TotalSizeGB = TotalSizeMB / 1024; if(TotalSize > 1) { formattedTotalSize = TotalSize.toFixed(2) + " Bytes"; //alert(formattedTotalSize); } if(TotalSizeKB > 1) { formattedTotalSize = TotalSizeKB.toFixed(2) + " KB"; //alert(formattedTotalSize); } if(TotalSizeMB > 1) { formattedTotalSize = TotalSizeMB.toFixed(2) + " MB"; //alert(formattedTotalSize); } if(TotalSizeGB > 1) { formattedTotalSize = TotalSizeGB.toFixed(2) + " GB"; //alert(formattedTotalSize); } if(TotalSize > 10485760) { var $file_warning = '
*** WARNING! *** The selected files exceed the upload limit! Your upload will fail.
The maximum allowed total file size is 10M.
The total size of all files selected to be uploaded is ' + formattedTotalSize + '

'; $("#file-upload-message").css( {"display" : "block"}); $("#file-upload-message").html( $file_warning); //$(".clear-input").css( {"display" : "inline-block"}); $(".file-upload-form input[type=submit]").prop( "disabled", true); } } }); function clearFileVal() { $("#inputControl").val(""); }