update
This commit is contained in:
45
v4_ci4/app/Libraries/QrCodeService.php
Normal file
45
v4_ci4/app/Libraries/QrCodeService.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries;
|
||||
|
||||
class QrCodeService
|
||||
{
|
||||
public function get(string $landing): string
|
||||
{
|
||||
require_once APPPATH . 'Libraries/phpqrcode-master/qrlib.php';
|
||||
|
||||
$url = base_url('v4/' . $landing);
|
||||
|
||||
ob_start();
|
||||
\QRcode::png($url, null, QR_ECLEVEL_M, 6);
|
||||
return base64_encode(ob_get_clean());
|
||||
}
|
||||
|
||||
public function generate(string $landing): string
|
||||
{
|
||||
// librairie QR
|
||||
require_once APPPATH . 'Libraries/phpqrcode-master/qrlib.php';
|
||||
|
||||
// URL finale (portable CI4)
|
||||
$url = base_url('v4/scan/' . $landing);
|
||||
|
||||
// dossier stockage
|
||||
$dir = WRITEPATH . 'qrcodes/';
|
||||
|
||||
// créer dossier si absent
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0755, true);
|
||||
}
|
||||
|
||||
// nom unique (multi-user safe)
|
||||
$filename = 'qr_' . bin2hex(random_bytes(8)) . '.png';
|
||||
|
||||
$filepath = $dir . $filename;
|
||||
|
||||
// génération QR
|
||||
\QRcode::png($url, $filepath, QR_ECLEVEL_M, 6);
|
||||
|
||||
// retour URL web
|
||||
return base_url('writable/qrcodes/' . $filename);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user