Pregunta

I'm starting a CakePHP Helper based on phpqrcode. My problem is that i can't get the generated png or svg file and force the browser to download it.

i want to when a person submit his text via Ajax, i generate a QR Code for him and force the browser to download it without saving the file on the server.

Here is a short example of the Helper:

App::import('Vendor', 'QRGenerator.phpqrcode'.DS.'qrlib');

class QRHelper extends AppHelper{

    function text($content= '') {

        QRcode::png($content);

    }   
}

In my view file:

<?php $this->QR->text('example text'); ?>

And my layout:

<?php  echo $this->fetch('content'); ?>

Thanks.

¿Fue útil?

Solución

Try this in your controller:

    $this->response->type('Content-Type: image/png');
    $this->response->download('qrcode.png');

Otros consejos

Try with return or echo QRcode::png($content); in text()

  function text($content= '') {

       return QRcode::png($content);

    }

Try with QR Code Helper:

  • Copy the "QrCodeHelper.php" to your "app/View/Helper" folder.

  • In the Controller add 'QrCode' to your helpers array.

  • In the view do for example:

    <? echo $this->QrCode->text('Hello World'); ?>
    
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top