I am trying to generate QR code for each users who signup for my website. I am going to send them QR code in email and they can use that QR code for sign-in. Doing some research work, I found phpqrcode. I tried the following code of lines, which is saving the name of the QR code image in the DB, but is not saving its image to the folder. How can I save the QR image into any folder(say for example: Uploads). SO once image is uploaded into the folder, I can easily send that image to the user.
So on submitting the register form, the following controller will be called and will save user as well as generate unique QR code for that user.
signupController.php
$user = \Model\User::loadFromPost();
if($user->save()){
$tempDir = $_SERVER['SERVER_NAME'].UPLOAD_PATH . 'qrcodes/';
$codeContents = $user->email;
$fileName = $user->id.md5($codeContents).'.png';
$pngAbsoluteFilePath = $tempDir.$fileName;
if (!file_exists($pngAbsoluteFilePath)) {
QRcode::png($codeContents, $pngAbsoluteFilePath);
$user->qrcode = $fileName;
$user->save();
} else {
echo 'File already generated! We can use this cached file to speed up site on common codes!';
echo '<hr />';
}
}
Here $_SERVER['SERVER_NAME']
is example.local/
(for Local) and https://www.example.com/
(for live server) and UPLOAD_PATH
is contents/images/uploads
. The above code, saves the name of QR code image file in DB but not saving the image of QR into the uploads folder.
Help is appreciated. Thanks.