connect_error) { die("Erro de conexão: " . $conexao->connect_error); } if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['nome']) && isset($_POST['telefone'])) { $nome = $conexao->real_escape_string(strip_tags(trim($_POST['nome']))); $telefone = $conexao->real_escape_string(strip_tags(trim($_POST['telefone']))); $telefone = preg_replace('/\D/', '', $telefone); if (!empty($nome) && !empty($telefone)) { $sql = "INSERT INTO contatos (nome, telefone) VALUES ('$nome', '$telefone')"; if ($conexao->query($sql) === TRUE) { header("Location: index.php?sucesso=1"); exit; } } } if (isset($_GET['baixar']) && $_GET['baixar'] === 'vcf') { $sql = "SELECT nome, telefone FROM contatos"; $resultado = $conexao->query($sql); if ($resultado && $resultado->num_rows > 0) { header('Content-Type: text/x-vcard; charset=utf-8'); header('Content-Disposition: attachment; filename="contatos_grupo.vcf"'); while ($linha = $resultado->fetch_assoc()) { echo "BEGIN:VCARD" . "\r\n"; echo "VERSION:3.0" . "\r\n"; echo "FN:" . $linha['nome'] . "\r\n"; echo "TEL;TYPE=CELL:" . $linha['telefone'] . "\r\n"; echo "END:VCARD" . "\r\n"; } exit; } } ?>