Sto usando JQuery per pubblicare i dati dei moduli e ho aggiunto questo nella mia funzione per permettere di inviare/caricare i file:JQuery multipart/dati ajax messaggio
mimeType:"multipart/form-data",
sto chiamando nel mio modulo HTML qui :
<form id="form1" method="post" action="/tickets/record?type=<?php echo $_GET["type"]; ?>&seq=<?php echo $_GET["seq"]; ?>" enctype="multipart/form-data" onsubmit="post_form('#form1');">
e cercando di gestire gli allegati in PHP con:
$attachment_array = array();
foreach($_FILES['ticket_update_files']['name'] as $key => $value) {
if(!$_FILES['ticket_update_files']['error'][$key]) {
}
}
ma la sua non recognisin g che tutti i file che sono stati selezionati.
La mia funzione completa jquery è:
function post_form(form_id, type, redir_url, loading_modal) {
type = type || '';
redir_url = redir_url || '';
loading_modal = loading_modal || '';
$(form_id).submit(function(e) {
var formObj = $(this);
var formURL = formObj.attr("action");
var formData = new FormData(this);
CheckRequired(e);
if(loading_modal === '1') { } else {
LoadModalBody('<h2 align="center">Loading...</h3><p align="center"><i class="fa fa-refresh fa-spin fa-5x"></i></p>', 'Loading');
}
$.ajax({
url : '/section' + formURL,
type: "POST",
data : formData,
mimeType:"multipart/form-data",
contentType: false,
cache: false,
processData:false,
success:function(data, textStatus, jqXHR) {
//alert(type);
if(type === 'modal') {
if(redir_url === '') {
LoadModal('/section' + formURL, '');
} else {
LoadModal('/section' + redir_url, '');
}
} else if(type === 'reload') {
if(redir_url === '') {
location.reload();
} else {
OpenPage(redir_url);
}
} else {
//close the loading modal
if(loading_modal === '1') { } else {
CloseModal();
}
//location.reload();
//$("body").html(data);
}
},
error: function(jqXHR, textStatus, errorThrown) {
//if fails
}
});
return false;
e.preventDefault();
});
}
Guardate [questa domanda] (http://stackoverflow.com/questions/10899384/uploading-both-data-and-files -in-one-form-using-ajax) forse può aiutarti. Guarda la risposta corretta, come ha formato l'AJAX. – matiaslauriti