I have a form and file input. I want to select images from another folder.
echo '<pre>';
var_dump($_FILES);
echo '</pre>';
When I send my form I need to see all selected images but I see only the last selected.
For example, the first time I select 2 files. After selecting 5 files and submitting my form I see only the last selected files, but I need to send all 7 files. Is it possible??
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" id="sell-images" name="images[]" multiple>
<input type="submit" value="submit">
</form>
I have this function for file counter:
$.fn.fileUploader = function (filesToUpload, sectionIdentifier) {
var fileIdCounter = 0;
this.closest("#sell-images").change(function (evt) {
var output = [];
for (var i = 0; i < evt.target.files.length; i++) {
fileIdCounter++;
var file = evt.target.files[i];
var fileId = sectionIdentifier + fileIdCounter;
filesToUpload.push({
id: fileId,
file: file
});
};
for(var z = 0; z < filesToUpload.length; z++)
{
evt.target.files[z] = filesToUpload[z]['file'];
}
console.log(evt.target.files)
});
return this;
};
Here is my onchange function:
$(document).ready(function() {
var filesToUpload = [];
var files1Uploader = $("#sell-images").fileUploader(filesToUpload, "images[]");
$("#sell-images").on('change',function(e) {
e.preventDefault();
Here I see in console all selected files from another folder
console.log($("#sell-images")[0].files);
var formData = new FormData();
for (var i = 0, len = filesToUpload.length; i < len; i++) {
formData.append("files", filesToUpload[i].file);
}
});
});
Here I have all selected files, but when I want to select a new file and send post in my PHP file, the global variable $_FILES
shows me only the last selected files.
How can I send my all selected files?
I can do it with another technique every time when selecting a file with JavaScript hide that input and create new but I don't want that.