Created
July 23, 2019 15:47
-
-
Save iDavidMorales/434d26cf44e40a92bb13ee964a08954a to your computer and use it in GitHub Desktop.
subir diferentes fotos al mismo tiempo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo $_FILES['archivo1']; | |
echo $_FILES['archivo2']; | |
echo $_POST['nombre']; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Upload de archivos con Ajax</title> | |
</head> | |
<body> | |
<form enctype="multipart/form-data" id="formuploadajax" method="post"> | |
Nombre: <input type="text" name="nombre" placeholder="Escribe tu nombre"> | |
<br /> | |
<input type="file" id="archivo1" name="archivo1"/> | |
<br /> | |
<input type="file" id="archivo2" name="archivo2"/> | |
<br /> | |
<input type="submit" value="Subir archivos"/> | |
</form> | |
<div id="mensaje"></div> | |
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script> | |
<script> | |
$(function(){ | |
$("#formuploadajax").on("submit", function(e){ | |
e.preventDefault(); | |
var f = $(this); | |
var formData = new FormData(document.getElementById("formuploadajax")); | |
formData.append("dato", "valor"); | |
//formData.append(f.attr("name"), $(this)[0].files[0]); | |
$.ajax({ | |
url: "recibe.php", | |
type: "post", | |
dataType: "html", | |
data: formData, | |
cache: false, | |
contentType: false, | |
processData: false | |
}) | |
.done(function(res){ | |
$("#mensaje").html("Respuesta: " + res); | |
}); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment