Creado por Luiz Cardamone
hace alrededor de 5 años
|
||
<!DOCTYPE html> <html lang="pt-br"> <head> <meta charset="utf-8"/> <link rel="stylesheet" type="text/css" href="css/style.css"> <script type="text/javascript" src="js/request"></script> <script type="text/javascript" src="js/jquery-3.4.1.min"></script> <script type="text/javascript" src="js/jquery.min"></script> <title>Curso Guanabara</title> </head> <body> <h1><a href="aula05.php?a=1852.01&b=4568.999"> Voltar </a></h1> <h1><a href="aula07.php"> Proxima </a></h1> <div> <label for="nome"> Nome: </label> <input type="text" value="" name="nome" id="nome"> </div> <label for="email"> Email: </label> <input type="text" value="" name="email" id="email"> </div> <button name="btn" id="btn" value="btn">Botão</button> </div> <div> <label for="ficheiro"> Enviar: </label> <input type="file" name="ficheiro" id="ficheiro"> </div> <script type="text/javascript"> var formData = new FormData(); document.getElementById("ficheiro").onchange = function(e){ if (e.target.files != null && e.target.files.length != 0){ formData.append("Fotografia", e.target.files[0]); } }; document.getElementById("btn").onclick = function(){ var getNome = document.getElementById("nome").value; var getEmail = document.getElementById("email").value; if (getNome != "" && getEmail != ""){ formData.append("nome", getNome); formData.append("email", getEmail); var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { alert(xhttp.responseText); } }; xhttp.open("POST", "aula08.php", true); xhttp.send(formData); }else{ alert("informaçoes vazias"); } }; </script> </body> </html>
<?php if($_POST){ $nome = $_POST['nome']; $email = $_POST['email']; $fotografia = $_FILES['Fotografia']; if(move_uploaded_file($fotografia['tmp_name'], $fotografia['name'])){ echo $nome.' '.$email; }else{ echo 'Erro no processo'; } } ?>
var formData = new FormData(); document.getElementById("ficheiro").onchange = function(e){ if (e.target.files != null && e.target.files.length != 0){ formData.append("Fotografia", e.target.files[0]); } }; document.getElementById("btn").onclick = function(){ var getNome = document.getElementById("nome"); var getEmail = document.getElementById("email"); if (getNome.value != "" && getEmail.value != ""){ formData.append("nome", getNome.value); formData.append("email", getEmail.value); var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { alert(xhttp.responseText); } }; xhttp.open("POST", "aula08.php", true); xhttp.send(formData); }else{ alert("informaçoes vazias"); } };
¿Quieres crear tus propios Apuntes gratis con GoConqr? Más información.