将二维码图像保存到 MySQLi 数据库 php
Save QR code image to MySQLi Database php
我想将 QR 码图像保存到我的数据库中,然后通过在其上调用 sql select 语句并在我的 [=14= 中的 table 上查看来检索它] 页。我知道调用 SQL 语句,我只是想知道是否可以这样做。
<?php
header("Content-type: image/png");
require_once ('vendor/autoload.php');
enter code here
try{
$itemName = $_POST['item'];
$itemDesc = $_POST['description'];
$itemPrice = $_POST['price'];
$itemQuantity = $_POST['quantity'];
$itemExpiry = $_POST['expiry'];
$itemCat = $_POST['categoryChoice'];
$itemOffers = $_POST['offers'];
} catch(Exception $e){
die($e->getMessage());
}
/*$itemData=$list->posteddata($posts = array($_POST['item'],$_POST['description'],
$_POST['price'],$_POST['quantity'],$_POST['expiry'],$_POST['categoryChoice'],$_POST['offers']));*/
$size = isset($_POST['size']) ? (int)$_POST['size'] : 300;
$padding = isset($_POST['padding']) ? (int)$_POST['padding'] : 10;
$code = ($itemName . $itemDesc . $itemPrice . $itemQuantity .
$itemExpiry . $itemOffers . $itemCat);
$qr = new Endroid\QrCode\QrCode();
$qr->setText($code);
$qr->setSize($size);
$qr->setPadding($padding);
$qr->render();
?>
可以将 QR 码存储在数据库中,为此您必须将文件路径存储在数据库中,然后检索它。
或者您可以将其存储为 ASCII,有关这方面的更多信息,您可以在@Pawel J. Wal 给出的示例中查看此答案:
How do I store the qrcode generated using phpqrcode into a db instead of in a filepath?
然后您可以在 html 中显示它 - 请参阅此示例了解更多信息:PHP display images from database
我想将 QR 码图像保存到我的数据库中,然后通过在其上调用 sql select 语句并在我的 [=14= 中的 table 上查看来检索它] 页。我知道调用 SQL 语句,我只是想知道是否可以这样做。
<?php
header("Content-type: image/png");
require_once ('vendor/autoload.php');
enter code here
try{
$itemName = $_POST['item'];
$itemDesc = $_POST['description'];
$itemPrice = $_POST['price'];
$itemQuantity = $_POST['quantity'];
$itemExpiry = $_POST['expiry'];
$itemCat = $_POST['categoryChoice'];
$itemOffers = $_POST['offers'];
} catch(Exception $e){
die($e->getMessage());
}
/*$itemData=$list->posteddata($posts = array($_POST['item'],$_POST['description'],
$_POST['price'],$_POST['quantity'],$_POST['expiry'],$_POST['categoryChoice'],$_POST['offers']));*/
$size = isset($_POST['size']) ? (int)$_POST['size'] : 300;
$padding = isset($_POST['padding']) ? (int)$_POST['padding'] : 10;
$code = ($itemName . $itemDesc . $itemPrice . $itemQuantity .
$itemExpiry . $itemOffers . $itemCat);
$qr = new Endroid\QrCode\QrCode();
$qr->setText($code);
$qr->setSize($size);
$qr->setPadding($padding);
$qr->render();
?>
可以将 QR 码存储在数据库中,为此您必须将文件路径存储在数据库中,然后检索它。
或者您可以将其存储为 ASCII,有关这方面的更多信息,您可以在@Pawel J. Wal 给出的示例中查看此答案:
How do I store the qrcode generated using phpqrcode into a db instead of in a filepath?
然后您可以在 html 中显示它 - 请参阅此示例了解更多信息:PHP display images from database