Downloading Images

0

I have the following code:

 <section class="margem-base-80 coluna  sombra-suave" id="recipiente-topo">

<h1 class="margem-topo-50 recipiente letra-branca">Gerar QRcode 
gratuitamente</h1>
<main class="em-linha" id="main-index">

<article class="recipiente" id="campo-qr">
  <form class="coluna" method="post">
    <label for="gerar-qr">Endereço web (URL)</label>
    <input type="text" name="code" id="code-input" 
placeholder="http://exemplo.com" required />
    <input type="hidden" name="gerar" value="s">
    <div>
    <button class="btn-azul margem-topo-50">Gerar QR code</button>
    </div>
  </form>
</article>

<?php

  if(isset($_POST['gerar'])) {

    require_once "interno/phpqrcode/qrlib.php";

    $valor = $_POST['code'];

    $code = $valor;

    QRcode::png($code, "Imagem_QRCODE_M.png", QR_ECLEVEL_M, 8);

    $qr= '<img id="tamanho-code" src="Imagem_QRCODE_M.png"/>';
  ?>  
<article class="recipiente" id="qr-campo">
  <?=$qr?>
</article>
  <?php
  } else { ?>
<article class="recipiente" id="qr-campo">
</article>
 <?php
  }
?>

</main>
</section>

This sample image is not in a database and is also not in a folder between the site files, it is only appearing on the site through my html code because it is a qr code image that the site generates by receiving the data via post. For some user to save this image on his computer he has to right click and then go to save images. How can I do to add my button to download this image as soon as the client clicks on it?

    
asked by anonymous 15.11.2017 / 19:03

1 answer

0

I'm not sure I understand, but if you want a button that downloads an image is this:

<a href="caminho_do_arquivo.txt" download="Nome do arquivo"><button>Download</button></a>

The download attribute causes the file mentioned in href to be downloaded with the given name in it and may contain spaces, but the name in href can not contain spaces

Note: For your html code aprarecer you need to put 4 spaces before type instead of

code ...

put:

código...

These 4 spaces is for the site to understand that what you are going to type is a block of code and not a code, so it is literally appearing a button, because you have put a <button>

Is that it?

    
15.11.2017 / 19:19