Per favore qualcuno dovrebbe mostrarmi come farlo usando javascript. perché sto usando Javascript e Ajax per caricare la pagina che farà l'upload e poi dopo l'uso Javascript e Ajax per inviare il modulo a uno script phpcome inviare un file e un campo di input utilizzando JavaScript e Ajax per inviare uno script php
function AddMultipleContact(){
var xmlhttp;
if(window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
var url = "url.php";
var group = document.getElementById("select-input").value;
var file = document.getElementById('file-name').files;
var variables = "select-input="+group+"&file-name="+file;
xmlhttp.open("POST", url, true);
// Set content type header information for sending url encoded variables in the request
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// Access the onreadystatechange event for the XMLHttpRequest object
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var data = xmlhttp.responseText;
document.getElementById("flash-message").innerHTML = data;
}
}
xmlhttp.send(variables); // Actually execute the request
}
Non restituisce nulla. sulla console javascript del mio browser questo è ciò che visualizza: FormData {append: function}. – Dreddy
E che cosa dovrebbe restituire? Si noti che è necessario modificarlo per adattarlo a ciò che si sta facendo e catturare i file sul lato server ecc. – adeneo
questo è ciò che ottengo quando faccio print_r ($ _ POST) nel mio script php: Array ( [------ WebKitFormBoundaryNXYmmE Content-Disposition: _form-dati; _name] => "selezionare" ------ WebKitFormBoundaryNXYmmE-- ) – Dreddy