How to create download link for qr code image in Laravel?

大城市里の小女人 提交于 2020-01-06 05:47:06

问题


I am using Laravel 5.2 and Simple QR code library for creating QR code. It works fine. Now i want to download generated QR code. Inspect element shows: I can save this image, right click on image>save image. But i want to make a link so that i can download this image with clicking download link button. Same as: this

mycode for creating qr code:

<div class="text-center">
    <img src="data:image/png;base64, {!! base64_encode(QrCode::format('png')->size(100)->generate('helloworld')) !!} ">
    <p>Scan me to return to the original page.</p>
</div>

Output of QR code:

Is there anyone who can help me regarding this issue? Thanks in advance.


回答1:


I think you might looking for download image of QR Code after generating a QRCode as image download

<a href="/images/myw3schoolsimage.jpg" download>

Or you can fixed filename

<a href="/images/myw3schoolsimage.jpg" download="filename">



回答2:


First decode on base64 then save into directory and finally show in image tag

file_put_contents('yourImgeName.png', base64_decode($dataString));

Finally

show image into img tag

<img src="yourImgeName.png" />

if you want to directly download image then used this

goto jsfiddle jsfiddle




回答3:


Myabe you can try using headers, telling browser or forcing browser to download the file

header('Content-Type: image/jpeg'); 
header("Content-length: " . filesize($NewFile)); 
header('Content-Disposition: attachment; filename="' . $NewFile . '"'); 
echo $content;
exit(); 

Where $NewFile can be your image file which gets generated. Or try changing image/jpeg to your suitable extensions.



来源:https://stackoverflow.com/questions/46558605/how-to-create-download-link-for-qr-code-image-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!