php - yii2 generates QR code and displays garbled characters
漂亮男人
漂亮男人 2017-05-16 13:06:35
0
4
545
use dosamigos\qrcode\QrCode;

public function actionQrcode()
{
    return QrCode::png('hello');
}

According to the original example, the picture cannot be displayed

漂亮男人
漂亮男人

reply all(4)
習慣沉默
use dosamigos\qrcode\QrCode;

public function actionQrcode() 
{
    header('Content-Type: image/png');
    ob_clean();
    return QrCode::png('hello');
}

Find the problem and add this to solve it

Thank you everyone for the solutions

我想大声告诉你

I haven’t used it, but you can check what the response header content-Type is and whether it is image/png

巴扎黑

Use incorrectly!
The parameter should be a url link---note that the link should be urldecoded
$url = urldecode($url);
QRcode::png($url);

世界只因有你
use dosamigos\qrcode\QrCode;
use yii\web\Response;

public function actionQrcode() 
{ 
    \Yii::$app->response->format = Response::FORMAT_RAW;
    return QrCode::png('hello');
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template