Me gustaría enviar una matriz de Javascript que contenga archivos a PHP usando AJAX
Los siguientes son 3 archivos que quiero enviar al lado de php. (Estas salidas provienen de console.log(document.getElementById("id").files[0] );
File { name: "img1.svg", lastModified: 1641853737982, webkitRelativePath: "", size: 2506, type: "image/svg+xml" } File { name: "img2.svg", lastModified: 1641853677323, webkitRelativePath: "", size: 1060, type: "image/svg+xml" } File { name: "img3.svg", lastModified: 1641853656789, webkitRelativePath: "", size: 1845, type: "image/svg+xml" }En este caso hay 3 archivos (Puede haber más o menos que eso).
Los 3 archivos están en una variable arrFiles . Entonces console.log (arrFiles) genera: Array [ File, File, File]
archivo JQuery
var form_data = new FormData(); var arrFiles = JSON.stringify(arrFiles) form_data.append("imgs", arrFiles); $.ajax({ url:url, method:"POST", data: form_data, contentType: false, cache: false, processData: false, success:function(data) { alert(data); } });archivo php
if(isset($_POST["imgs"])){ //Would like to handle each image separately. $imgs = json_decode($_POST['imgs']); //May be something like : foreach($_POST["imgs"] as $img){ $movePath = "images/".$img['name']; move_uploaded_file($img["tmp_name"], $movePath); } return; }¿Hay alguna manera de manejar esto?