[英]CakePHP: download generated QR Code
I'm starting a CakePHP Helper based on phpqrcode . 我正在启动基于phpqrcode的CakePHP Helper。 My problem is that i can't get the generated png or svg file and force the browser to download it.
我的问题是我无法获取生成的png或svg文件,无法强制浏览器下载它。
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. 我想当一个人通过Ajax提交文本时,为他生成一个QR码,并强制浏览器下载它而不将文件保存在服务器上。
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. 谢谢。
Try with return or echo QRcode::png($content); 尝试使用return或echo QRcode :: png($ content); in text()
在text()中
function text($content= '') {
return QRcode::png($content);
}
Try this in your controller: 在您的控制器中尝试以下操作:
$this->response->type('Content-Type: image/png');
$this->response->download('qrcode.png');
Try with QR Code Helper : 尝试使用QR Code Helper :
Copy the "QrCodeHelper.php" to your "app/View/Helper" folder. 将“ QrCodeHelper.php”复制到“ app / View / Helper”文件夹中。
In the Controller add 'QrCode' to your helpers array. 在Controller中,将“ QrCode”添加到您的助手数组。
In the view do for example: 在视图中,例如:
<? echo $this->QrCode->text('Hello World'); ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.