[英]CakePHP: download generated 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'); ?>
謝謝。
嘗試使用return或echo QRcode :: png($ content); 在text()中
function text($content= '') {
return QRcode::png($content);
}
在您的控制器中嘗試以下操作:
$this->response->type('Content-Type: image/png');
$this->response->download('qrcode.png');
嘗試使用QR Code Helper :
將“ QrCodeHelper.php”復制到“ app / View / Helper”文件夾中。
在Controller中,將“ QrCode”添加到您的助手數組。
在視圖中,例如:
<? echo $this->QrCode->text('Hello World'); ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.