CakePHP:下载生成的QR码 [英] CakePHP: download generated QR Code
本文介绍了CakePHP:下载生成的QR码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开始使用基于 phpqrcode 的CakePHP助手。我的问题是,我不能得到生成的png或svg文件,并强制浏览器下载它。
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.
我想要当一个人通过Ajax提交他的文本,我生成一个QR码为他和强制浏览器下载它,而不保存在服务器上的文件。
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'); ?>
我的布局:
<?php echo $this->fetch('content'); ?>
谢谢。
推荐答案
在您的控制器中尝试此操作:
Try this in your controller:
$this->response->type('Content-Type: image/png');
$this->response->download('qrcode.png');
这篇关于CakePHP:下载生成的QR码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文