I developed custom multiple file upload feature like follows
this is the whole code for above module
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="file_count"></div>
<input type="file" id="uploadFile" name="FileUpload" multiple="multiple" />
<div id="upload_prev"></div>
Script
var fileCount = 0;
var showFileCount = function() {
$('#file_count').text('# Files selected: ' + fileCount);
};
showFileCount();
$(document).on('click', '.close', function() {
$(this).parents('span').remove();
fileCount -= 1;
showFileCount();
})
$('#uploadFile').on('change', function() {
var filename = this.value;
var lastIndex = filename.lastIndexOf("\\");
if (lastIndex >= 0) {
filename = filename.substring(lastIndex + 1);
}
var files = $('#uploadFile')[0].files;
for (var i = 0; i < files.length; i++)
{
if (files[i].size < 5242880)
{
$("#upload_prev").append('<span>' + '<div class="filenameupload">' + files[i].name + ' abc</div>' + '<p class="close" >X</p></span>');
}
else
{
alert("File size is more than 5MB");
event.preventDefault();
false;
}
}
fileCount += files.length;
showFileCount();
});
CSS
.filenameupload {
width: 98%;
}
#upload_prev {
border: thin solid #000;
width: 65%;
padding: 0.5em 1em 1.5em 1em;
}
#upload_prev span {
display: flex;
padding: 0 5px;
font-size: 12px;
}
I'm trying to stop files, that size more than 5mb attaching to this 'uploadFile' multiple file input, using above code.
but it can 'append' div items properly and can't stop attaching files(size more than 5mb) to above 'uploadFile' multiple file input
How can I resolve this
EDIT
This is a ASP.NET MVC Application, this is how I'm getting files from backend
[HttpPost]
public ActionResult SomeAction(ModelClass model)
{
var attchaedfiles = Request.Files;
...
}