search

Home  >  Q&A  >  body text

php - yii2 generates QR code and displays garbled characters

use dosamigos\qrcode\QrCode;

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

According to the original example, the picture cannot be displayed

漂亮男人漂亮男人2767 days ago539

reply all(4)I'll reply

  • 習慣沉默

    習慣沉默2017-05-16 13:08:35

    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

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-16 13:08:35

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

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-16 13:08:35

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

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-16 13:08:35

    use dosamigos\qrcode\QrCode;
    use yii\web\Response;
    
    public function actionQrcode() 
    { 
        \Yii::$app->response->format = Response::FORMAT_RAW;
        return QrCode::png('hello');
    }

    reply
    0
  • Cancelreply