$(document).ready(function() { var $limit_message = '
'; 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 = '