Aleesd
Aleesd

Reputation: 31

Unable to update the input file list

I am trying to add multiple images by using Laravel and it works fine by using the following command.

<input type="file" id="images" name="images[]" onchange="preview_image();" multiple accept="image/*"><br/>
<div id="image_preview"></div>

<script>

function preview_image() 
{
 var total_file=document.getElementById("images").files.length;
 for(var i=0;i<total_file;i++)
 {
  $('#image_preview').append("<img src='"+URL.createObjectURL(event.target.files[i])+"'>");
 }
}

</script>

but when i try to add more images, input file list clear and add the new list. I want to know how to keep the old files when i add new files.

Upvotes: 1

Views: 125

Answers (1)

Thomas
Thomas

Reputation: 537

Shouldn't preview_image() have argument event.

Upvotes: 1

Related Questions