I am tryins to convert an array of images in blob format and send to script php to process the data but the array of blobs is not sending correctly, i dont know why. My input in html is this:
<div class="form-group">
<input id="imagen" onchange="send()" type="file" name="imgs" multiple="true" class="form-control required" >
</div>
And my script in javascript is this:
<script>
var y='#imagen';
var z;
var blobs;
function send(){
x=trans(y);
};
function trans(v) {
var file = document.querySelector(v).files;
for (i = 0; i < file.length; i++) {
var reader = new FileReader();
reader.readAsDataURL(file[i]);
reader.onloadend = function () {
blobs[i]=reader.result;
}
}
console.log(blobs.length);
}
</script>
I'm trying to send the array blob to script php throught ajax call:
var form = $('#for_addH')[0];
var formData = new FormData(form);
formData.append("blobs",JSON.stringify(blobs));
$.ajax({
type: "POST",
url: "phpfunc/posadas/nueva_habitacion.php",
contentType:false,
processData:false,
cache:false,
data: formData,
timeout: 180000
})
So, my problem is that the array is not sending correctly. help please.