[ "method" => "GET", "header" => "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36\r\n" ], "ssl" => [ "verify_peer" => false, // Evita fallos si el certificado SSL tiene algún desajuste "verify_peer_name" => false, ] ]; $contexto = stream_context_create($opciones); // Intentamos obtener la imagen usando el contexto configurado $image_data = @file_get_contents($foto_url, false, $contexto); if ($image_data !== false) { $foto_base64 = base64_encode($image_data); } $vcard_file = "BEGIN:VCARD\r\n"; $vcard_file .= "VERSION:3.0\r\n"; $vcard_file .= "N:{$apellidos};{$nombre};;;\r\n"; $vcard_file .= "FN:{$nombre} {$apellidos}\r\n"; $vcard_file .= "ORG:{$empresa}\r\n"; $vcard_file .= "TITLE:{$titulo}\r\n"; $vcard_file .= "TEL;TYPE=work,voice:{$telefono}\r\n"; $vcard_file .= "EMAIL;TYPE=work:{$email}\r\n"; $vcard_file .= "URL:{$web}\r\n"; // Si logramos descargar y codificar la foto, la metemos a la fuerza en el archivo if (!empty($foto_base64)) { $vcard_file .= "PHOTO;ENCODING=b;TYPE=JPEG:{$foto_base64}\r\n"; } $vcard_file .= "END:VCARD\r\n"; // Cabeceras HTTP para forzar al móvil a descargar y abrir el contacto header('Content-Type: text/vcard; charset=utf-8'); header('Content-Disposition: attachment; filename="contacto_' . strtolower($nombre) . '.vcf"'); echo $vcard_file; exit; } // 2. Construir la cadena de texto estática $vcard = "BEGIN:VCARD\n"; $vcard .= "VERSION:3.0\n"; $vcard .= "N:{$apellidos};{$nombre};;;\n"; $vcard .= "FN:{$nombre} {$apellidos}\n"; $vcard .= "ORG:{$empresa}\n"; $vcard .= "TITLE:{$titulo}\n"; $vcard .= "TEL;TYPE=work,voice:{$telefono}\n"; $vcard .= "EMAIL;TYPE=work:{$email}\n"; $vcard .= "URL:{$web}\n"; $vcard .= "PHOTO;VALUE=URI:{$foto_url}\n"; $vcard .= "END:VCARD"; // 3. Generamos la URL dinámica a la que apuntará el QR para desencadenar la descarga $protocolo = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') ? "https" : "http"; $url_actual = $protocolo . "://" . $_SERVER['HTTP_HOST'] . strtok($_SERVER['REQUEST_URI'], '?'); $url_descarga_dinamica = $url_actual . "?descargar_vcf=1"; ?>