<?php
  require 'phpqrcode/qrlib.php';

  $texto = "";
  $archivo = "";
  if(isset($_POST["texto"])){
    $texto = trim($_POST["texto"]);
    if($texto == ""){
      $aviso = "Escriba un texto para generar el codigo QR";
    } else {
      $archivo = "qr_" . uniqid() . ".png";
      QRcode::png($texto, $archivo, QR_ECLEVEL_L, 6);
      if(!file_exists($archivo)){
        $archivo = "";
      }
    }
  }
?>
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Generar QR</title>
</head>
<body>
    <h3>1. GENERAR CODIGO QR</h3>
    <form action="generar.php" method="post">
        Texto: <input type="text" name="texto" value="<?php echo htmlspecialchars($texto); ?>" size="40" required>
        <input type="submit" value="GENERAR QR">
    </form>

    <?php
      
      if($archivo != ""){
        echo "<p>Texto: <b>" . htmlspecialchars($texto) . "</b></p>";
        echo "<p><img src='" . $archivo . "' width='260'></p>";
        echo "<p><a href='" . $archivo . "' target='_blank'>Ver tamano completo</a></p>";
      }
      echo "<p><a href='indice.php'>Volver al inicio</a></p>";
      
    ?>
</body>
</html>
