简体   繁体   English

如何将QR码作为图像文件存储到Mysql数据库中

[英]How to store QR code as image file in to Mysql Database

I`m implementing a simple application using Laravel. 我正在使用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. 您可以将图像转换为base64,然后将其存储为文本。 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 有关如何编码的更多信息,请访问http://php.net/manual/en/function.base64-encode.php和解码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. 您还可以将图像存储为BLOB ,与以base64编码的图像相比,开销较小,并且不会被索引为可搜索的字符串。

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. 我认为您不需要存储实际的QR码。

A QR code is merely a way of representing a string of characters. QR码仅仅是表示字符串的一种方式。 Often people will put a URL into the QR code. 人们通常会将URL放入QR码中。

You can probably just store the source data into your db, and generate the QR from the data. 您可能只是将源数据存储到数据库中,然后从数据中生成QR。

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. 如果数据是URL,则使用QR的设备应能够链接到该URL,这会将其带回您的应用程序。 You could put parameters on the end of the URL to allow your app to retrieve the data from your db for that user. 您可以将参数放在URL的末尾,以允许您的应用从您的数据库中检索该用户的数据。
You could even use a signed URL so that the end user cannot change it. 您甚至可以使用签名的URL,以便最终用户无法更改它。

Here is an article that I found that may help. 这是我发现可能会有所帮助的文章。 It's not laravel specific, but will help with the QR code understanding. 它不是laravel特有的,但将有助于理解QR码。 https://www.kerneldev.com/2018/09/07/qr-codes-in-laravel-complete-guide/ https://www.kerneldev.com/2018/09/07/qr-codes-in-laravel-complete-guide/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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