In general, there is the following code https://jsfiddle.net/xyz78apr/

function readImagesURL(input) { if (input.files) { for (var i = 0; i < input.files.length; i++) { (function(file) { var reader = new FileReader(); reader.onload = function(e) { var id = $('.image').length; var image = '<div class="col-sm-2">'; image += '<img src="'+e.target.result+'" class="image_upload_preview img-thumbnail">'; image += '<input type="file" id="image-'+id+'" class="image" name="file['+id+']" value="'+e.target.result+'" accept="image/*">'; image += '<button type="button" class="change_img btn btn-block btn-primary">Изменить</button>'; image += '</div>'; $('.gallery .row').append(image); } reader.readAsDataURL(file); })(input.files[i]); } } } 

The problem is that when sending to the server I get an empty array. For example, I chose 3 images to upload, I get

 ["file"]=> array(5) { ["name"]=> array(3) { [1]=> string(0) "" [2]=> string(0) "" [3]=> string(0) "" } 

If after performing readImagesURL, the image is manually changed to a single image, then it gets to the server, if in the loop, then an empty array.

The idea is to make it so that we choose an unlimited number of images to upload, we get a preview, and each image can be changed before uploading to the server.

  • Give the code to send to the server. And you can even code that handles on the server - Alexey Shimansky
  • Yes, on the server, the usual var_dump($_FILES); - Guest
  • Okay, but you can take a look at the server upload script?)) - Alexey Shimansky
  • There MVC framework, we simply send the form to action, and in action var_dump($_FILES); and so far, there is no further sense to move, the array is empty: ( - Guest
  • Well, without the sending code, nothing can be said ..... I of course today received the title of winner in the battle of psychics. But it still does not work anywhere) - Aleksey Shimansky

0