CakePHP:下载生成的QR码

时间:2014-01-29 12:14:45

标签: php cakephp http-headers qr-code

我正在基于phpqrcode启动CakePHP Helper。我的问题是我无法获取生成的png或svg文件并强制浏览器下载它。

我想当一个人通过Ajax提交他的文本时,我为他生成一个QR码并强制浏览器下载它而不保存服务器上的文件。

以下是帮助者的简短示例:

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

class QRHelper extends AppHelper{

    function text($content= '') {

        QRcode::png($content);

    }   
}

在我的视图文件中:

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

我的布局:

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

感谢。

3 个答案:

答案 0 :(得分:1)

尝试使用return或echo QRcode :: png($ content);在text()

  function text($content= '') {

       return QRcode::png($content);

    }

答案 1 :(得分:1)

在你的控制器中试试这个:

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

答案 2 :(得分:0)

尝试QR Code Helper

  • 将“QrCodeHelper.php”复制到“app / View / Helper”文件夹。

  • 在Controller中将'QrCode'添加到助手数组中。

  • 在视图中执行例如:

    vidPage
相关问题