简体   繁体   中英

How to store QR code as image file in to Mysql Database

I`m implementing a simple application using Laravel. just wondering, when I send qr code in email text, does qr code need to be stored in database first to Specify file pass for the image??

If that answer is yes, is there any way that I`m able to store qr code without using form tag?

You can do it converting image to base64 and then store it as text. for more information how to encode visit http://php.net/manual/en/function.base64-encode.php and for decode http://php.net/manual/en/function.base64-decode.php

example encode:

$file_encoded = base64_encode(file_get_contents($file)); //this is stringed data. save this in database. 

example decode:

$file_encoded = base64_decode ($file_encoded); //this will be file.

You could also store the image as a BLOB , which has less overhead as a base64 encoded image and would not be indexed as a searchable string.

Even better might be to just store links to binaries in your database as opposed to the data itself.

I don't think you need to store the actual QR code.

A QR code is merely a way of representing a string of characters. Often people will put a URL into the QR code.

You can probably just store the source data into your db, and generate the QR from the data.

If the data is a URL, the device consuming the QR should be able to link to the url which will bring it back to your application. You could put parameters on the end of the URL to allow your app to retrieve the data from your db for that user.
You could even use a signed URL so that the end user cannot change it.

Here is an article that I found that may help. It's not laravel specific, but will help with the QR code understanding. https://www.kerneldev.com/2018/09/07/qr-codes-in-laravel-complete-guide/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM