I have a problem. I have to submit a form that allows multiple documents to be attached. Each <input type="file">
gives the option to add more documents.
My question is, I want to process that form with JavaScript
and then send it to php
to record the information in my DB. How can I do it?
I was thinking of creating an array of the files
using the attribute name
and traversing them with the function map
in one array
or creating an array with all the temp_name
in one array.
And currently in javascript
the process like this:
function registroSolicitud(){
var datosSolicitud = new FormData($( "#form-solicitud" )[0]);
$.ajax({
type: "POST",
url: "/centro/panel/controller/controlador_solicitud.php",
data: datosSolicitud,
contentType: false,
processData: false,
cache: false,
success: function(data){
}
});
return false;
}
The problem is that if I do it this way I get the <input type="file">
a PHP
.
If each
input
has aname
different one,PHP
you must receive them according to this name separately. But ifinput
they have them the samename
as an array, eg:name="adjuntos[]"
,PHP
you receive them as such and you must use a loop to iterate through them.It
input
would be more or less like this:The way you're sending them with
ajax
is fine. If you want to see what is coming to youPHP
, useprint_r($_FILES);