max
max

Reputation: 3716

is there any way to findout how many file has been selected through input field(type=file)?

i have a upload script that works with html5 file api and i want to write a backend iframe solution for internet "waste of code" explorer

so i have a form which i load through iframe and when the form is submitted , i add a loading template to the parent document

here is my html code

<form enctype="multipart/form-data" method="post" action="<?php echo $action; ?>" >
<input type="file" name="files[]"  id="files" multiple> 
<input name="profile_id" type="hidden" value="<?php echo $profile_id; ?>">
<input name="" type="button" value="Button" onClick="add_loder();">
</form>

here is my add_loder function

<script>
var d = $(window.frameElement).parent(); 

function add_loder()
{
    if($('#files').val().length == 0 )
    return false;


    var template = '<div class="preview">'+
                        '<span class="imageHolder">'+
                            '<img class="prv" src="<?php echo IMAGE_URL; ?>done.png" />'+
                            '<span class="uploaded"></span>'+
                        '</span>'+
                        '<div  class="ph" >'+
                            '<img src="<?php echo IMAGE_URL; ?>load_square.gif" style="margin-right:45%;width:27px;height:27px">'+
                        '</div><div class="area"><textarea  class="picarea"> </textarea><input type="button" value="<?php echo $confirmLable; ?>" class="conf">'+
                        '<input  type="button" value="<?php echo $deleteLable; ?>" class="del"><input class="id" type="hidden" value="0"></div>'+
                    '</div>'; 

    d.append(template);
    $('form').submit();

}
</script>

but this only adds one loading to the page

i want to add a loading for each selected file so i have to know how many file has been selected

Upvotes: 0

Views: 73

Answers (1)

Musa
Musa

Reputation: 97672

$('#files')[0].files it a collection of the selected files so try $('#files')[0].files.length

Upvotes: 2

Related Questions