Вопрос : Как сохранить файлы на сервер?
<div class="order__upload">
<div class="upload upload-JS">
<label class="upload-btn-JS">
<div class="upload__box upload__add-photo">
<input type="file" multiple name="images[]">
<div class="upload__plus"><span></span><span></span></div>
<div class="upload__text">Добавить фото</div>
</div>
</label>
</div>
</div>
/ LOAD IMAGE
var fileCollection = [];
var formData = new FormData(fileCollection);
var files = [];
console.log(files);
$('.upload__add-photo').on('change', function(e){
files=e.target.files;
files2=e.target.files;
console.log("--------after");
console.log(files);
$.each(files2, function(i, file){
fileCollection.push(file);
console.log("fileCollection");
console.log(fileCollection);
var reader = new FileReader();
reader.readAsDataURL(file);
console.log("files");
console.log(files);
reader.onload = function(e){
var template = '<div class="upload__box upload__your-photo">'+
'<img src="'+e.target.result+'">'+
'<div class="delete-photo" onclick="delPrewievPhoto($(this).parent().index(), $(this).parent())">Удалить</div>'+
'</div>';
var valueBoxPhoto = $('.upload__your-photo').length;
console.log("files onload");
console.log(files);
console.log("fileCollection onload")
console.log(fileCollection);
if(valueBoxPhoto > 1){
$('.upload-btn-JS').hide();
}
if(valueBoxPhoto == 0){
$('.upload-JS').prepend(template);
} else {
$('.upload__your-photo').eq(-1).after(template);
}
}
})
files=fileCollection;
console.log("----------------");
console.log(files);
console.log("----------------");
})
console.log("end");
console.log(files);
function delPrewievPhoto(indexArray, currentItem){
fileCollection.splice(indexArray, 1);
currentItem.remove();
console.log(fileCollection);
if($('.upload__your-photo').length < 4){
$('.upload-btn-JS').show();
}
}