Skip to content

Instantly share code, notes, and snippets.

@iDavidMorales
Created July 23, 2019 15:47
Show Gist options
  • Save iDavidMorales/434d26cf44e40a92bb13ee964a08954a to your computer and use it in GitHub Desktop.
Save iDavidMorales/434d26cf44e40a92bb13ee964a08954a to your computer and use it in GitHub Desktop.
subir diferentes fotos al mismo tiempo
<?php
echo $_FILES['archivo1'];
echo $_FILES['archivo2'];
echo $_POST['nombre'];
?>
<!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