1

I have this form in html for multiple file uploading .

<form class="userform" method="post" action="upload.php" role="form"   enctype="multipart/form-data" >
        <input  name="title" type="text" ><br/>
        <input  type="file" name="media[]" >
        <div class="filesupload">
          <input type="file" name="media[]" >
        </div>
<script>
 $(document).on("click",".add-new-file",function()
            {
                $('.filesupload').append('<input  name="media[]" type="file"  >');
            });
</script>
</form>

I will get input files by javascript and send to upload.php for uploading. but I don't know how to get files values in javascript.

3
  • What do you mean by "files values"? Do you want the file name, size, or content? Commented Jan 23, 2015 at 14:03
  • ok! I will get files by $_FILES["media"] in upload.php but I don't Know how to send by $(ajax) Commented Jan 23, 2015 at 14:06
  • you might need to read this developer.mozilla.org/en-US/docs/… first. Also its possible only with browsers that support xhr2 caniuse.com/#feat=xhr2 Commented Jan 23, 2015 at 14:11

1 Answer 1

3

If you using HTML5

   var fileList = document.getElementById("yourInput").files;
    for(var i = 0; i < fileList.length; i++) {
        //Do something with individual files
    }

Using jquery

$("input[name=file1]").change(function() {
    var names = [];
    for (var i = 0; i < $(this).get(0).files.length; ++i) {
        names.push($(this).get(0).files[i].name);
    }
    $("input[name=file]").val(names);
});​
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.